Skip to content
This repository has been archived by the owner on Feb 26, 2019. It is now read-only.

Taggd is not a constructor #52

Closed
ifalldev opened this issue Jan 19, 2017 · 13 comments
Closed

Taggd is not a constructor #52

ifalldev opened this issue Jan 19, 2017 · 13 comments

Comments

@ifalldev
Copy link

ifalldev commented Jan 19, 2017

Hi, I'm trying to use the package through NPM on MeteorJS but I'm facing a strange issue.

My implementation:

npm install --save taggd

and so

import Taggd from 'taggd';

const img = document.querySelector('#myImage');
const taggd = new Taggd(img);

But when I run the application this error appears on my console: Uncaught TypeError: Taggd is not a constructor.

And if i print a log on my console before the new Taggd (like this console.log(Taggd)) the result is a empty object!

But if I try to access the Taggd constructor on the console (just after the error has appeared) the return is the constructor function! And I can do all of my implementation there!

I would appreciate some help!

Thank you!

@timseverien
Copy link
Owner

timseverien commented Jan 19, 2017 via email

@ifalldev
Copy link
Author

ifalldev commented Jan 19, 2017

Yeah! It works with import 'taggd'.
I'm using babel-compiler@6.13.0.

My script is just that which I passed before.

I installed it with node, imported the package and tried to use it on MeteorJS 1.4.2.
(If I'm not seeing what you need about my script, show me please)

Thank you!

@timseverien
Copy link
Owner

timseverien commented Feb 1, 2017

Ugh, having issues fixing this. Apparently, ES2015-style imports expects a format that is achieved by exporting ES2015-style. Unfortunately this affects AMD imports and the global “export” as well. Moment.js used to have similar issues.

Apparently, a module field in package.json is semi-standardised across different bundlers, allowing you to specify a path to a ES2015 file.

Would you please be so kind to test this change?

npm install timseverien/taggd#es2015-import

@sharpner
Copy link

sharpner commented Feb 2, 2017

I am running into the same issue. So maybe some feedback helps:
I am currently testing with the es2015-import branch and it helps a bit.

This works:

import Taggd from 'Taggd';
import {Tag} from 'Taggd';

but what I would need:

import {Tag, Taggd} from 'Taggd';

does not work.

Hope it helps and thx for fixing this :-)

@timseverien
Copy link
Owner

Good point. I might have an idea to solve it, but I'll have to look into it. Thanks for trying it out :)

@timseverien
Copy link
Owner

I’ve made two files, each exporting the library differently.

  • umd.js exports Taggd, and the Tag class can be found as a static field in Taggd.
  • modern.js export exports Taggd and Tag as named exports.

This means that those who import Taggd via ES2015 imports get access to both Taggd and Tag separately, whereas those who use the UMD bundle get access to the Taggd class and will have to use Taggd.Tag to create tags. This is slightly inconvenient, but I’m hoping this makes Taggd compatible for both import strategies.

To clarify this, I have added a section on the README.

Can either @ifalldev or @sharpner check whether Taggd imports as expected for an ES2015+ codebase? Again, you can fetch the branch using npm install timseverien/taggd#es2015-import. Make sure it installs the latest version of that branch instead of fetching it from cache or anything.

If all looks well, I’m going to merge the branch, release a new major and close this issue :)

@sharpner
Copy link

sharpner commented Feb 7, 2017

hey thanks for the fast updates.

I just did a quick check with webpack and import Taggd, {Tag} from 'taggd'; works for me now!

@sharpner
Copy link

are you going to merge this anytime soon? :)

@timseverien
Copy link
Owner

I might do it this weekend. I have had like 0 spare time past two weeks 😑

@sharpner
Copy link

yeah no worries :-) thanks for the update

@timseverien
Copy link
Owner

I forgot to say: it’s merged in 4.0.0 now :)

@sharpner
Copy link

sharpner commented Mar 3, 2017

thx :)

@ifalldev
Copy link
Author

Hey! Sorry for my late feedback!

Everything went fine for me using import syntax in 4.0.0. Thanks for this!

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

No branches or pull requests

3 participants