-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Closed
Labels
Description
Bug report
What is the current behavior?
install @babel/runtime-corejs3
for file index.js
import '@babel/runtime-corejs3/helpers/esm/defineProperty'
and run webpack ./index.js
ERROR in ./node_modules/@babel/runtime-corejs3/helpers/esm/defineProperty.js 1:0-74
Module not found: Error: Can't resolve '../../core-js/object/define-property' in 'xxx\node_modules\@babel\runtime-corejs3\helpers\esm'
@ ./index.js 1:0-58
beta.29
is working properly on this.
but if we manually edit line 1 in file ./node_modules/@babel/runtime-corejs3/helpers/esm/defineProperty.js
from
import _Object$defineProperty from "../../core-js/object/define-property";
to
import _Object$defineProperty from "../../core-js/object/define-property.js";
and this issue goes away.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
Other relevant information:
webpack version: 5.0.0-beta.30
Node.js version: 12.16.1
Operating System: win10 2004
Additional tools:
at the time I'm using @babel/runtime-corejs3@^7.11.2
tibdex, Tsury, blakmatrix, crobinson42, EvHaus and 34 more
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
EvHaus commentedon Sep 13, 2020
I'm having a very similar problem after upgrading from beta.29 to beta.30 but with this different import:
Clearing the local filesystem cache (
rm -rf node_modules/.cache
) didn't help. But rolling back to beta.29 worked for me as well.duan602728596 commentedon Sep 13, 2020
I also encountered the same problem, which seems to be caused by enabling mjs experiments, and I did not find a way to close mjs experiments.
sokra commentedon Sep 13, 2020
These are all the same issues. In .mjs files or .js files with a package.json with
"type": "module"
imports need to be fully specified. This means you need to have an extension.That how ESM in node.js is defined, and you are opting in into this behavior by using the .mjs extension resp the field in the package.json.
We didn't enforce this behavior in previous versions while this was still experimental in node.js, but it left this status, so I feel ok with enforcing this and pointing out these incorrect packages.
You could disable that with
{ test: /\.m?js/, type: "javascript/auto" }
inmodule.rules
.ocdi commentedon Sep 14, 2020
@sokra I have extremely similar symptoms, even with the above
module.rules
suggestion. Rolling back tobeta.29
compiles successfullyI tried various positions of adding the rule, setting type in other potential rules involving .js/typescript that might affect it, but none solved this module not found issue.
I suspect babel need to fix their code to support this correctly, otherwise there will be many people having issues with this on webpack5.
For now I am sticking to
beta.29
.duan602728596 commentedon Sep 14, 2020
After configuring like this, there will still be some modules can't resolve.
sokra commentedon Sep 14, 2020
btw this is not an webpack-only error. If you run
import("@babel/runtime-corejs3/helpers/esm/defineProperty.js")
in node.js you get an error too:Ok I tried that by myself and it doesn't work correctly. Instead you have to do that to change the resolving for these modules:
type: "javascript/auto"
might be added to fully disable the different behavior for .mjs files, but that doesn't affect the resolving. It only affects e. g. how interop with non-ESM modules is handled.alexander-akait commentedon Sep 14, 2020
@sokra maybe we can put this option to https://webpack.js.org/configuration/resolve/ (by default
true
), I'm afraid of too many projects use wrong paths inimport
, using:with babel/ts/other loaders will increase the size an complex of configurations
alexander-akait commentedon Sep 14, 2020
Also I think we need docs this
/cc @chenxsan , can you open an issue? Maybe we should rewrite all
import
in docs on using extensionsvankop commentedon Sep 14, 2020
@evilebottnawi
thats how Node.js resolves.. Maybe we need to point in docs workaround..
alexander-akait commentedon Sep 14, 2020
@vankop yes, I known, in theory we can improve error messages out of box, like:
Because now you might think something wrong with resolving (not found, etc)
186 remaining items