-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
WebPack emulates require('underscore') incorrectly #2852
Comments
Sorry to hear that this is biting you, @dmaicher. However I cannot reproduce this with Underscore 1.10.2 and underscore.string 3.3.5. Is there anything special about your setup? |
Thanks for your fast reply 😊 I'm using |
Here is a minimal reproducer: https://github.com/dmaicher/underscore_issue_2852 |
Here is your problem: That import path, Lines 17 to 18 in 5d8ab5e
whereas the Apparently, WebPack nowadays assumes ES modules by default but has a fallback for CommonJS imports. I guess you'll have to configure it somehow to not assume ES modules or to ignore the I'm closing this now because this is a WebPack issue rather than an Underscore issue. Feel free to continue commenting, though. |
@jgonggrijp thanks for checking 👍 I was able to fix it by adding an alias for resolving in the webpack config: But this seems a bit odd to me. Many other packages I use specify Webpack takes the first field it finds in the order I'm curious why it only fails for underscore but seems to be working for other packages 😊 |
If you name those other packages, I'm happy to take a look. Anyway, https://github.com/rollup/rollup/wiki/pkg.module The documentation you linked to hints at a perhaps slightly less ugly solution, which is to set |
Just in case here are some packages I use that have both https://www.npmjs.com/package/vuejs-datepicker |
Related webpack issue: webpack/webpack#5756 |
Yes, that is your issue. Although there also seems to be something off with the way WebPack is emulating CommonJS when resolving to the // converting modules/index-all.js to ES3
var underscoreESModule = {
'default': _,
map: _.map,
filter: _.filter,
// ...
}; // in your code that imports underscore
var _ = underscoreESModule; The latter line would make sense if you were doing this: import * as _ from 'underscore'; but what you're actually doing is equivalent to this: import _ from 'underscore'; and the right way to translate that to ES3 in WebPack would be as follows: var _ = underscoreESModule['default']; This is also exactly the problem that other people are running into in webpack/webpack#5756. Other build tools such as Browserify and Rollup handle this more intelligently. Just saying... |
This reply just solved an issue I've been battling for 12 freaking days in our webpack build. THANK YOU! |
This reply just solved an issue I've been battling for 12 freaking days in our webpack build. THANK YOU! |
I updated from 1.9.2 to 1.10.2 today and for me mixins are not working anymore when using
require('underscore');
This fails with
TypeError: _.camelcase is not a function
:but this works:
The text was updated successfully, but these errors were encountered: