Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in declaring the Class in es6 project. #102

Open
MVSTEJA opened this issue May 26, 2017 · 11 comments
Open

Issue in declaring the Class in es6 project. #102

MVSTEJA opened this issue May 26, 2017 · 11 comments

Comments

@MVSTEJA
Copy link

MVSTEJA commented May 26, 2017

I am using the font face observer in my react es6 project this way --

import FontFaceObserver from 'fontfaceobserver';
const openSansObserver = new FontFaceObserver('Open Sans');

Or even this , as is mentioned in the docs -
var FontFaceObserver = require('fontfaceobserver');
const openSansObserver = new FontFaceObserver('Open Sans');

and its throwing error such as this.
_fontfaceobserver2.default is not a constructor. / FontFaceObserver is not a constructor

Not using modules?
You can also download a copy and manually include it in your project. You can then use the global Font­Face­Observer constructor to load your fonts. This somehow works for me as shown below, but above two should either be broken now or there is something in the way you guys export your module. If i am wrong please ignore this. Else kindly change the the export.

Working Version -

require('fontfaceobserver');
const openSansObserver = new FontFaceObserver('Open Sans');//eslint-disable-line no-undef

@bramstein
Copy link
Owner

Hmm, this looks specific to your project or transpiler. If you have a reproducible test case I can have a look.

@rkmax
Copy link

rkmax commented Jun 6, 2017

I'm having the same issue, I'm using https://github.com/react-boilerplate/react-boilerplate as it

@bramstein
Copy link
Owner

I checked out react-boilerplate and I can't reproduce this. It works out of the box (the boilerplate already includes Font Face Observer).

@MVSTEJA
Copy link
Author

MVSTEJA commented Jun 7, 2017

Can you check my repo @bramstein. https://github.com/MVSTEJA/React-Redux-BoilerPlate-Es6. Against this path :- React-Redux-BoilerPlate-Es6/src/main.js .

@bramstein
Copy link
Owner

@MVSTEJA Can you try upgrading to the 2.x branch of Font Face Observer? The only major API change is that the check method has been renamed to load (line 20 in src/main.js). I think the 2.x branch also fixes the problem you're seeing.

@renestalder
Copy link

Do you plan to publish a full es6 version with proper imports at some point?

@bramstein
Copy link
Owner

@renestalder Yea, that might be a good idea. I was waiting for browser support to catch up (re: modules), and then I'll have a look at it.

@vincentwoo
Copy link

vincentwoo commented Apr 7, 2018

I would really love if FFO was written as an ES6 module, with dist outputs still suitable for direct browser inclusion. Right now, using FFO in ES6 involves still doing a require. Going the ES6 route also makes it easier to import the promise/promiseless versions more simply.

It's uncomfortable to have consumers of FFO rely on the output of google's closure compiler, instead of allowing their own build tools to perform tree shaking. FFO, as a relatively small library, likely does not benefit much from closure's advanced compilation settings. Users consuming the minified library file (the only option) will not be able to plumb source maps all the way through FFO, and will also likely suffer a double minification penalty.

@scsskid
Copy link

scsskid commented Aug 14, 2019

yes please +1
great script anyways, thanks for the effort!

@z1haze
Copy link

z1haze commented May 19, 2020

confirming this issue. does not work with es6 imports.

@rafagsiqueira
Copy link

Having issues with imports as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants