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

[bugfix] Make auto locale loading for node not mess webpack, fixes #4031, #2979, #3872 #4042

Closed
wants to merge 1 commit into from

Conversation

ovangle
Copy link
Contributor

@ovangle ovangle commented Jun 27, 2017

Reopening this PR now that tests are passing.

Cannot import the locale relatively, since the code exists
in a different location in the bundled ES5 module than it
does in ES6.

In order to run tests locally (where the external 'moment'
library can't be loaded), fall back to using the relative import.

Cannot import the locale relatively, since the code exists
in a different location in the bundled ES5 module than it
does in ES6.

In order to run tests locally (where the external 'moment'
library can't be loaded), fall back to using the relative import.
@maggiepint
Copy link
Member

Yeah, that's a good change. Thanks.

@ichernev
Copy link
Contributor

ichernev commented Aug 3, 2017

@ovangle can you provide some context please? What is broken, when, why.

@ovangle
Copy link
Contributor Author

ovangle commented Aug 3, 2017

@ichernev
Sorry if I wasn't clear, this is a fix for issue #4031 (and #2979, #3872). When building with webpack and when using the ES6 sources, the build process was not able to locate the file node_modules/moment/src/lib/locale/locales/<name>, because it (rightly) doesn't exist. When using the ES5 sources, the import resolves to node_modules/moment/src/locales/<name>, which does exist.

Because webpack has no knowledge of the runtime it ignores the try/catch around the code and errors out.

The fix is to import from moment/locales/<name> because that always exists, however this doesn't work in your test environment because a library cannot declare itself as a dependency, so the original import has to be provided as a fallback.

I've stated elsewhere that I'd like this block of code removed entirely, because it isn't an ES6 compliant import (ES6 imports must be statically available), but that would be a breaking change, so I've "fixed" it for 2.x.x and will submit a fix for 3.x.x in the next couple of days.

@ovangle
Copy link
Contributor Author

ovangle commented Aug 3, 2017

Actually looking at my changes now, I'm not so sure it resolves the issue... I tested installing from a git dependency before I added the fallback option, but I can't remember if I tested it after adding the fallback, I just noticed the unit tests were failing and it seemed like the obvious fix.

Webpack might ignore the fact that the second require is inside a catch and still error out. I'll test it tomorrow and get back to you.

@ovangle
Copy link
Contributor Author

ovangle commented Aug 5, 2017

I installed it on a private project it using a git dependency. The require inside the catch statement is ignored by webpack. So yeah, I think it's fixed.

@ichernev
Copy link
Contributor

ichernev commented Aug 7, 2017

Merged in 49819dc

@ichernev ichernev changed the title Fix #4031 - Missing ES6 module during tree shaking [bugfix] Make auto locale loading for node not mess webpack, fixes #4031, #2979, #3872 Aug 7, 2017
@ichernev ichernev closed this Aug 7, 2017
ichernev added a commit that referenced this pull request Aug 7, 2017
[bugfix] Make auto locale loading for node not mess webpack, fixes #4031, #2979, #3872
@ovangle ovangle mentioned this pull request Aug 17, 2017
tqc added a commit to tqc/moment that referenced this pull request Oct 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants