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

Use with Parcel #14

Closed
jnnkB opened this issue Jun 8, 2020 · 4 comments
Closed

Use with Parcel #14

jnnkB opened this issue Jun 8, 2020 · 4 comments

Comments

@jnnkB
Copy link
Contributor

jnnkB commented Jun 8, 2020

Hi,

I'm trying to bundle my javascript, css, … with parcel. Unfortunately I couldn't get the tag-picker to work.

When I try to use tag-picker like so:

import "@taufik-nurrohman/tag-picker";

document.addEventListener("DOMContentLoaded", function () {
  new TP(document.querySelector(".tags-field"));
});

I get the following error:

ReferenceError: TP is not defined script.js:4:2
    parcelRequire<["script.js"]</< script.js:4

But when I change the last line of tag-picker to the following it works:

})(window, document, "TP");

I don't really know why and if that change will cause other errors. I applied the changes on my own fork (https://github.com/jnnkB/tag-picker) so I could open an pull request if wanted.

Here's a zip that contains all the code:
parcel_tag_picker.zip

Thanks a lot!

@jnnkB jnnkB changed the title tag-picker parcel Use with parcel Jun 8, 2020
@taufik-nurrohman
Copy link
Owner

@taufik-nurrohman
Copy link
Owner

taufik-nurrohman commented Jun 9, 2020

Ah, so, Parcel environment does not reference the this scope to window?

Or, is it due to the ES6 module scope?

What will happen if you do:

console.log([window, this, this === window]);

?

@jnnkB
Copy link
Contributor Author

jnnkB commented Jun 9, 2020

When I create a code snippet containing your code I get the following output:

(3) […]
0: Window http://localhost:1234/
1: Object {  }
2: false
length: 3
<prototype>: Array []

I don't know why this happens it's just an observation.

@taufik-nurrohman
Copy link
Owner

I don't know why this happens it's just an observation.

It’s a standard behavior of ES6 module implementation.

I am mostly making JavaScript plugins for the browsers and have never checked it if it would work with any package bundling system, because personally I don’t really like the module concept. I just put that package.json file there and then let it go.

Since you are a real user that encounter this problem regarding the ES6 standard and you found out that the only solution to make it work without declaring a UMD-like snippet within my code (that I don’t like too), then I would agree to you if you want to make such pull request.

So that I can share this issue to my other JavaScript plugins then. Thanks.

@taufik-nurrohman taufik-nurrohman changed the title Use with parcel Use with Parcel Jun 11, 2020
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

2 participants