webpack: webpack 5.0.0-beta.30 Module not found: Error: Can't resolve '../../core-js/object/define-property'
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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 39
- Comments: 73 (25 by maintainers)
Commits related to this issue
- Update webpack 5 resolving (#17095) On the latest beta of webpack 5 resolving fails with the below error and according to https://github.com/webpack/webpack/issues/11467 is due to the imports in this... — committed to vercel/next.js by ijjk 4 years ago
- add breaking change info for fullySpecified resolving #11467 — committed to webpack/webpack by sokra 4 years ago
- add breaking change info for fullySpecified resolving #11467 — committed to webpack/webpack by sokra 4 years ago
- Update webpack 5 resolving (#17095) On the latest beta of webpack 5 resolving fails with the below error and according to https://github.com/webpack/webpack/issues/11467 is due to the imports in this... — committed to HitoriSensei/next.js by ijjk 4 years ago
- WIP: upgrade webpack 5 not working due to: https://github.com/webpack/webpack/issues/11467 — committed to johncalvinroberts/craglog by johncalvinroberts 4 years ago
- Disable fully-specified module extension resolution for js, mjs modules Ref: https://github.com/webpack/webpack/issues/11467 — committed to openculinary/frontend by jayaddison 4 years ago
- Fix webpack module not found error when using esm Default behaviour: When the nearest "package.json" file of a module contains "type" field with a value of "module", one should provide the extension ... — committed to Kozea/webpackozea by deleted user 3 years ago
- Fix webpack module not found error when using esm Default behaviour: When the nearest "package.json" file of a module contains "type" field with a value of "module", one should provide the extension ... — committed to Kozea/webpackozea by deleted user 3 years ago
- Can't resolve './nonIterableSpread' problemin i18next was solved by this article: https://github.com/webpack/webpack/issues/11467 — committed to code4history/MaplatCore by kochizufan 3 years ago
- upgrade webpack (!) Also includes two webpack configuration changes. See: https://webpack.js.org/migrate/5/#update-outdated-options and https://github.com/webpack/webpack/issues/11467#issuecomment... — committed to mercycorps/toladata by axoplasm 2 years ago
- fix(no-release): plugin docusaurus webpack config to fix js resolve [webpack issues](https://github.com/webpack/webpack/issues/11467) — committed to sakitam-gis/vis-engine by sakitam-fdd a year ago
- chore(release): 1.1.0 [skip ci] # [1.1.0](https://github.com/sakitam-gis/vis-engine/compare/v1.0.4...v1.1.0) (2023-01-30) ### Bug Fixes * **math:** Matrix3 subtract method and Matrix4 add/sub/multi... — committed to sakitam-gis/vis-engine by semantic-release-bot a year ago
- chore(release): 1.0.0 [skip ci] # 1.0.0 (2023-02-07) ### Bug Fixes * **core:** `Resource` subclass missing `removeStats` ([2a0e3f7](https://github.com/sakitam-gis/vis-engine/commit/2a0e3f7accb61420... — committed to sakitam-gis/vis-engine by semantic-release-bot a year ago
- Config workaround for an error processing async@3's dist/async.mjs async@3 includes an ESM version dist/async.mjs, which Webpack by default prefers over the CommonJS version dist/async.js. Unfortunat... — committed to derbyjs/derby-webpack by ericyhwang 10 months ago
- Config workaround for an error processing async@3's dist/async.mjs (#24) async@3 includes an ESM version dist/async.mjs, which Webpack by default prefers over the CommonJS version dist/async.js. Unfo... — committed to derbyjs/derby-webpack by ericyhwang 10 months ago
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.Hey, I just wanted to chime in with something that might help folks. I just upgraded a home-grown config library to Webpack 5, bumped all my dependencies, and have been integrating this into my various projects. A JavaScript project using @material-ui exploded with these errors when I did this.
The resolve/fullySpecified fix mentioned above did nothing for me. I was stuck here for a bit, but then I found something that did work.
I’m using yarn, and there’s the “resolutions” option you can add to the package.json. @material-ui was pulling in @babel/runtime 7.11.1, and I wanted to make sure it was on the latest 7.12.5. So I added this resolution to my package.json:
And viola, everything is fixed now. The fullySpecified option isn’t even needed anymore. The app appears to be working fine, although more testing is definitely required.
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
.Ran into this issue with Babel 7.11.~ after updating to Webpack 5. Enumerating the error messages here so other people looking for help will find the fix here.
Fix (as mentioned above):
Add the following rule to your
webpack.config.js
: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.I believe that
fullySpecified: true
is a very good default option, because it encourages everyone to work towards the future of ES Modules and to stop supporting anything else that is not spec-compliant. Library authors will have incentive to fix their libs so that they work in Webpack with defaults that enforce ES Module standards. This will make the ecosystem a lot better and progress towards everything working with native ES Modules.Imagine if
fullySpecified: false
was the default: we’d have a whole new generation of Webpack where people are writing code that isn’t ES Module compliant, and therefore encouraging further fragmentation between real ES Module code and ES-Module-like code.@trusktr Try to install the latest
@babel/runtime
bynpm i @babel/runtime -D
, it works for me.Happening to me as well. Upgrading Webpack from beta.29 to beta.30, not doing literally anything else, breaks the build:
@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)
@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
.I have what I think might be a similar problem using
apollo-upload-client
, which usesextract-files
:The author is adamant that it’s not a problem with their library.
I have the
fullySpecificed: false
rule in place, but it’s not making a difference. Since the issue lies in a third party library and not our source code, do I need to modify the additional rule to specifically target that library?I’m pretty surprised that we got this many comments in without anybody linking to https://github.com/microsoft/TypeScript/issues/16577 – I’d bet dollars to doughnuts that all the libraries that people are having trouble with were compiled from Typescript, which 1) encourages users to write extensionless relative import specifiers, then 2) does not give any way to convert those to valid (extension-included) specifiers.
(I’m also having this problem with a compiled-from-TS library…)
@evilebottnawi just upgraded to babel 7.12 and removed the
fullySpecified
rule. Works as intended 👍I also encounter similar issue but the message is like:
To what I know this is an error when
@babel/runtime
is importing its internal module (both insidehelpers/esm
folder), es module resolution of node should not forbid internal imports, it only affects how other modules import it from external.Having tried quite a few things to debug this, I found eventually that deleting lockfile and node_modules and reinstalling resulted in a working build
I’m not having luck with the
fullySpecified: false
solution. When I add that to my module rules and try the latestrc.0
build I end up with this failure:And sometimes this one:
The same issues don’t happen on beta.29. Is anyone else seeing similar problems?
If you’re using chainWebpack, then it’s like this
chain.module.rule(“mjs-rule”).test(/.m?js/).resolve.set(fullySpecified, false);
There is no problems on webpack side, please read the error message, problem in
@lume/element
package, they used ES module syntax, but don’t use.js
/.mjs
extensions inimport
, try to run this code in node or browsers without webpack, you will get the problemsThis worked for me - but I needed to add a dollar sign to the end of the regular expression (
/\.m?js$/
) or webpack 5 started failing on JSON files (it matched .json as well as .mjs and .js).After configuring like this, there will still be some modules can’t resolve.
babel-plugin-proposal-private-methods
from babel/core@7.14.0 worked as well and doesn’t require the extra webpack rule for node_modulesAlso needed to manually remove older versions of babel from
yarn.lock
You might need to refresh your npm/yarn lockfile.
Check that your currently installed runtime is at least 7.12.0 with
npm ls @babel/runtime
I really just used this role in 5.1.0 and it worked
@evilebottnawi I got it. Maybe this issue https://github.com/babel/babel/issues/12058 . Babel 7.12 may solve this issue.
There is no problems on webpack side
This fixed it for me
@chooban this problem not related to original problem, already reported https://github.com/webpack/enhanced-resolve/issues/256
@doberkofler yes, because it is wrong, this code will not work on node or browser, so webpack starts to use strict rules for this, it is even not webpack problem, try to use
node@14
and run this code, you will get the same problem@ScriptedAlchemy Already pinned https://github.com/webpack/webpack 😄
Yes, it is bug on Babel side, they will do release on the next week
@evilebottnawi Thanks. Does it mean webpack 5 has no problem but material-ui or babel (plugins) has problem?
Error messages:
I’ve been investigating and trying workarounds. However the error still exists with stable
v5.0.0
.{ fullySpecified: false }
or another workarounds which are proposed in related issue does not work well now.Also seeing this issue with beta 30->32 as well, 29 still works ok. All of the errors we’re getting are coming from Material UI via @babel/runtime. Adding the
fullySpecified: false
workaround seems to do the trick.Can anyone solve this please… i am getting it in the browser console 😃
Uncaught TypeError: (0 , codecs_data_structures_1.getBytesCodec) is not a function at ./node_modules/@solana/spl-token-metadata/lib/cjs/state.js (state.ts:7:1) at options.factory (react refresh:6:1) at __webpack_require__ (bootstrap:22:1) at fn (hot module replacement:61:1) at ./node_modules/@solana/spl-token-metadata/lib/cjs/index.js (index.ts:4:1) at options.factory (react refresh:6:1) at __webpack_require__ (bootstrap:22:1) at fn (hot module replacement:61:1) at ./node_modules/@metaplex-foundation/mpl-token-metadata/node_modules/@solana/spl-token/lib/cjs/extensions/tokenMetadata/actions.js (actions.ts:4:1) at options.factory (react refresh:6:1)
@doberkofler please read the error message, problem in
fullcalendar
https://github.com/fullcalendar/fullcalendar/blob/master/packages/core/package.json#L12, it say what it is ES modules
But https://github.com/fullcalendar/fullcalendar/blob/master/packages/core/src/main.ts#L2 :
import './vdom'
is invalid and even not work on node, it should beimport './vdom.js'
reexport also invalid, they should have
.js
at the end of exports@doberkofler For my part I have dependencies which use
@babel/runtime-corejs2
, I had to remove the entry fromyarn.lock
then runyarn
to install the latest version.I have the same issue as @wojtekmaj.
{ fullySpecified: false }
doesn’t work for me. I use webpack 5 (stable release) alongside latest versions of babel packages (core-js, etc.).