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

es6 import not working #31

Closed
Nopzen opened this issue Mar 24, 2018 · 6 comments · Fixed by #36
Closed

es6 import not working #31

Nopzen opened this issue Mar 24, 2018 · 6 comments · Fixed by #36

Comments

@Nopzen
Copy link
Collaborator

Nopzen commented Mar 24, 2018

After developing #30 i stumbled across an issue, where I was not able to use the es6 import syntax, to import this module in a non ejectedcreate-react-app setup.

create-react-app before ejecting it has its own magical webpack setup, and upon digging abit I found a post on the webpack tracker that talked about multiple builds in npm module package file, and how webpack by default uses the browser key.

Upon inspecting our setup i saw the lib/standalone.js was the one stored on the browser key, when i tried to import this module the following error happens:

skaermbillede 2018-03-23 kl 21 49 53

I tried to swap the standalone.js with the bundle.js and then everything works, I think there is a bug with the way standalone.js exports this module to the browsers.

I did find this post also on the webpack issue tracker, webpack/webpack#1979 suggesting how you can order mainFields in your webpack resolver, but I haven't tested this or if this is remotly related to this case here.

@ichbinedgar
Copy link

ichbinedgar commented Mar 26, 2018

I solved it by using
import 'zipcelx'
instead of
import zipcelx from 'zipcelx'

@Nopzen
Copy link
Collaborator Author

Nopzen commented Mar 26, 2018

@ichbinedgar Wont you need the from, to declare from which module you need to import from?

For the fun of it i tried it out and as expected an error occured, 'zipcelx' not defined.

@ichbinedgar
Copy link

ichbinedgar commented Mar 26, 2018

@Nopzen I'm not an expert, but what I understand is that is equivalent to
require('library_name');

https://stackoverflow.com/questions/42251503/javascript-es6-import-without-a-name

I did not use create-react-app, so I'm not sure why is not working for you. It maybe the webpack configuration.

@egeriis
Copy link
Owner

egeriis commented Mar 28, 2018

import 'zipcelx'; is perfectly valid. Just not the way it's supposed to work. I want to get this fixed asap, I'll use create-react-app to verify the build.

@guushamann
Copy link

guushamann commented Apr 25, 2018

i made a es6 branch, I think this is how it should work, but i am not sure how to combine it with standalone

I also noticed that when using the module it was global (window.zipcelx)

If you are interested,check the changes I made
https://github.com/guushamann/zipcelx/tree/es6-version-only

changes are in
https://github.com/guushamann/zipcelx/blob/es6-version-only/rollup.config.js
https://github.com/guushamann/zipcelx/blob/es6-version-only/src/zipcelx.js

usage:
import zipcelx from 'zipcelx'
or with tree shaking
import { zipcelx } from 'zipcelx'

@egeriis
Copy link
Owner

egeriis commented Apr 30, 2018

@guushamann Thank you for your contribution. There are a few things misunderstood from your changes:

Tree shaking

There's nothing to tree shake in zipcelx, there's only one export, so you don't get any benefits of doing a default vs named import. Neither should be the case for modules w/multiple exports, but that's irrelevant in this case.

Rollup config

We with to have all three builds still. The standalone build is to support the requests made by a few people: #19 (#13)

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

Successfully merging a pull request may close this issue.

4 participants