-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
5.0.0-rc.3 fails with tslib #11613
Comments
Seeing this too with @sentry/browser |
@orta This is caused by microsoft/tslib#127
Unrelated from this adding an |
@sokra the The issue is solely because webpack and node disagree on what shape importing a cjs module should take. In node, when an es module imports a cjs module, the cjs module is made available, in full, as the default value of the import. Some statically determinable names may also be made available as named exports, as of a recent patch, but tslib's exports aren't statically determinable (because of its UMD wrapper pattern), so in node it won't have any named exports. Meanwhile in webpack, only named exports get made.... these two views of the module system are mutually incompatible. Either
One of the two needs to change, though, there's nothing we could do that isn't a major break in some other way that fixes it. |
I thought webpack did make the |
Yeah, it would seem to be. Both |
I specificaly tested this and it seemed to always include |
Further, if tslib isn't being imported but it is being require'd the "import" path shouldn't be applying in exports in the first place at all. So I'm confused why it's even using the module verison to begin with. |
@guybedford |
|
And we don't do it |
|
I see rxjs has a modules path. So it's just the issue in #11613 (comment) then. Ok glad to hear "imports" doesn't apply unnecessarily and thanks for clarifying @evilebottnawi. It should be possible to support |
@guybedford don't worry we will found better way, you can see |
Although, as an aside, |
Yes, the behavior for the default export with Here is a simplified example: // a.js
exports.__esModule = true;
exports.named = 42; // b.js
exports.__esModule = true;
exports.named = 42;
exports.default = 123; import a from "./a.js"
import b from "./a.js"
console.log(a, b); Node.js will log We could do a As workaround add |
@sokra but again, shouldn't webpack be using the |
no Note that there is also a |
If you're not faithfully emulating what |
Oh sorry missed that. Should be fine then |
RollupJS supports this I believe. I feel quite strongly the default invariant should be maintained whenever possible. |
The exports field is not really relevant for this problem. If you point |
I wouldn't tie |
Yes, but that's deprecated. It also checks only
I feel like // a.js
exports.__esModule = true;
exports.named = 42;
|
We only have a condition directing to a wrapper module because Is there a way to get webpack to prioritize a |
Because Node.js has no treatment for __esModule. To ignore the default, is to break all interop of all __esModule cases between Node.js and Webpack. For Node.js it was important to always maintain the invariant that This is why I say this is one of those points to meet in the middle. |
No, but there is a |
So long as |
It's clearly worse if we have to individually configure every tool. I would strongly recommend alignment on the semantic edge case causing this issue. SystemJS has supported both |
@sokra |
I brought this up many times. Node.js always brought up technically problems with aligning with the correct |
@sokra I invented that pattern for Traceur in 2014. |
microsoft/tslib#130 that definitely the better way compared to using the |
I am not maintaining "cross-compatible wrapper code", and no sane individual should be expected to do as such. I will just use the exports condition that makes webpack go back to unconditionally including the pure-es6 sources, as it did before we added the |
But while I do have a workaround for this case, I'll be clear here: This is undoubtedly a real issue that is going to continue to haunt both |
I think it's pretty rare, as hardly anyone writes code with |
For better or for worse, TS has supported when targeting import mod = require("mod");
export = mod; if So it's not quite limited to handwritten |
This does affect any other transpiled package with an ESM wrapper (admittedly, where Node.js can't detect the exports). |
I see the problem, but from webpack point of view that's the correct behavior. If the module |
Even if you use this example when |
Yeah, that's where I thought this was going - |
If you really want to solve that with "type": "module",
"exports": {
".": {
"module": "./tslib.js",
"import": "./modules/index.js",
"default": "./tslib.js"
},
"./": "./"
} But I would recommend to change tslib.js to ESM in the next major and offer a transpiled tslib.cjs version in addition: "type": "module",
"exports": {
".": {
"module": "./tslib.js",
"require": "./tslib.cjs",
"default": "./tslib.js"
},
"./": "./"
} This doesn't lead to duplication in webpack. It only leads to duplication in Node.js, but that's not relelvant here. The benefit of using an ESM version is that more optimizations are possible for ESM. |
Yeah, we'll be adding an extra condition shortly; we're just ginning up some tests. But again, the differences in the interop story are a real issue - working around it by including an esm copy of the sources in webpack won't necessarily be an option for everyone else... |
fixed in tslib |
Nice! 🍰 |
Bug report
What is the current behavior?
Running
[email protected]
fails when importingrxjs
(which usestslib
):If the current behavior is a bug, please provide the steps to reproduce.
Details of this error are reproducible in https://github.com/philcockfield/webpack5-tslib-error
The demo repo is a minimal webpack configuration using
ts-loader
that importsrxjs
. It also behaves this way with vanilla JS and babel loaders.What is the expected behavior?
The page loads with no errors. This demo repo works fine with
[email protected]
and then cleanly fails by flipping the version up to5.0.0-rc.3
Other relevant information:
webpack version: 5.0.0-rc.3, 5.0.0-rc.4
Node.js version: 12.16.3
Operating System: MacOS (10.15.7)
Additional tools: -
The text was updated successfully, but these errors were encountered: