-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
2.2.0-rc.4's es6 modules' "module" usage detection seems to be broken #3917
Comments
Adding to import root from './_root.js';
/** Detect free variable `exports`. */
var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports; |
By exporting And importing this is considering it an esm module. Esm has no access to local |
Checking for the existence of a variable should not trigger the warning. It's valid JavaScript regardless of context. If possible, it would be better to detect assigning to the free variables in question: exports.foo = 1;
// or
module.exports = {}; |
Was just asking about this. Thanks for the follow-up |
RE:me
Ah, that might still falsely trigger it for UMD juggling which is safe. Maybe instead of a hard error treat it as a warning? Or get fancy and only throw the warning if the |
I don't think that would catch all the ways this could happen, may it be in a try/catch, or even indirect assignment a-la I think it's better as a warning, instead of a hard error, with the possibility of disabling the warning on certain locations in the config. It'd prevent a vast majority of edge case bugs related to this. |
I think it is. Moment's code where the error appears looks slightly different, but I'd bet that it's the case for it too. |
For the falsely flagged cases, yes. For common UMD patterns see the umdjs repo. You may find most UMD cases check for the existence of free variables before use, so tripping a |
🤔 We do have support based on the webpack's module resolution pattern respects this resolution spec. Just as workaround? |
I think thats a good start. |
It looks like it's also breaking on if (module.hot)
module.hot.accept (...); |
In that case I think the warning (so instead of a straight error a warning) should be triggered since you're assuming the existence of |
@jdalton: You're right. Although shouldn't there be a different way of implementing HMR now? Like through importing the |
@SEAPUNK Thank you for submitting your first issue btw!!! 🙇 |
Haha, no problem. I've been using Webpack for a while; it's a great project! Someday I hope to contribute to it. |
Never too late to start :-D :-D The suspect plugin starts from here is: CommonJSInHarmonyDependencyParserPlugin.js I believe either in the individual DependencyBlocks or here, we need to conditionally hook into only certain types of ast aware logic. Like "Was this a free global access or assignment?". |
It looks like it needs |
@dkrutsko the One thing that won't work is, say, passing the |
redux and redux-form both use lodash-es, which means they produce this same bug |
That's a maybe. redux uses the |
One or the other is broken by this issue. They're the only libraries using lodash-es in my failing build. |
rc5 fails for me at runtime now instead of compile time with the same "exports is not defined" error as above. I'm using ES6 stage2 - not TS, but with redux-form and its lodash-es dependency |
Tested @TheLarkInn's commit, and it perfectly resolves the problem. Thanks a lot! Before applying #3971: ("exports is not defined" error) After applying #3971: (Works perfectly) |
@TheLarkInn seems working only if I target commonjs |
I think it's another issue, see for more details #3972 |
I can confirm that the example given by @niieani above (Aurelia loader detecting NodeJS) is fixed by rc5. |
@TheLarkInn: I tried the #3971 fix, and now get the runtime error: As I assume that is the expected error, couldn't a more helpful error message be displayed? |
I was still getting some errors, but applying #3971 fixed them. If you don't want to revert but some third-party dependencies have errors, removing 'module' from your main field might help:
|
I don't know if it's related or not at all but I have a parser plugin for import { A } from "x";
A.B(); Then my plugin code is not called anymore. Whereas this would: // Assume A is global
A.B(); Is that expected or an issue? |
@jods4 this is expected, as the parser (and plugins) only look for "free vars". If A is defined it's not a free var. |
I tried |
@todd-richmond was this fixed for you? I found this to be the culprit for
|
@mmahalwy RC7 and GA both resolved my problems - thx |
@phyllisstein I am getting the same error under the exact same conditions. Were you able to solve this? When I try to use export like so This seems to be related to the babel |
@stenvdb IIRC my diagnosis was similar to yours and I wound up removing that plugin. That said, I spent a few minutes trying to get back into that bad state and could not, with either If I'm reading @sokra's comment and the release notes for |
@phyllisstein Thanks for the response, I'm also on 6.23.0, in fact did a global update for all packages. But I'm definitely seeing the same error everybody here is talking about, and it's caused by that If it helps, I'm quite new to this and I'm working with a tutorial for which you can find the source files here: https://github.com/morkro/tetrys |
@stenvdb Yowza, aside from wanting to gently and lovingly discourage you from spending even another second in that repo, it's hard to know what else to say without seeing the code you're working with. If you want to push that to GitHub I'll happily find a moment to take a look, but I don't have enough to go on from here. |
@phyllisstein Wow thanks. I've uploaded my source files: https://github.com/Stenvdb/redux-test The repo mentioned above (tetrys) is just some source files for this tutorial btw https://www.sitepoint.com/redux-without-react-state-management-vanilla-javascript/ |
@stenvdb Didn't want to keep polluting this issue; see my PR at https://github.com/Stenvdb/redux-test/pull/1. ✨ |
Any news on this? I'm also getting the same error when using babel's |
I think I have the most simple set up and I'm still getting this error.
|
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
External modules (symbol-observable, moment) no longer compile with this release.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
Bundle compiles fine
It doesn't appear that moment and symbol-observable modules actually use
module.exports
at the locations Webpack says there is an error.For example,
symbol-observable/es/index.js
:Gives the error:
The text was updated successfully, but these errors were encountered: