pkg.main should be an es5 module not es6 #10849
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BACKGROUND
I'm using foundation-sites 6.4.3 in a ruby on rails app with webpacker (ie. webpack and babel), and importing the javascript code into my webpacker pack via an es6 import (ie.
import 'foundation-sites'
). This works great in development, however, when I try to compile my javascript for production, I get a mysterious error:Seems like theres another report of the issue here
INVESTIGATION
It looks like uglifier is choking on es6 syntax. However, what's strange about that is that uglifier is used to post process the code, after transpiling to es5, so it should never see that syntax. What's more, so far as I'm aware, babel doesn't normally transpile node_modules, so why am I seeing es6 syntax coming from a nodule module? 🤔
ISSUE
It looks like foundation-sites switched the
main
value inpackage.json
from an es5 file to an es6 file in version 6.4.0 (see d02be4b). As far as I'm aware,main
is always supposed to point to precompiled es5 file. There's some discussion about how to expose an es6 module in package.json (see jsforum/jsforum#5), withjsnext:main
being the current favourite, but this should be a precompiled file with anyimport
statements removed (again, see the previous github issue), andnpm.js
(which is the currentmain
value) hasimport
statements.FIX
For now I've reverted the change to
main
so that it points to an es5 file. This resolves the compile issue for me.This shouldn't break anythinfg for users just importing everything, but might cause issues if someone wants to do a more complex import (ie.
import {foo} from
'foundation-sites`).A longer term fix might be to add
jsnext:main
to package.json, and changenpm.js
so that it's a single precompiled file that does not includeimport
statements.