webpack & babel-polyfill: Can't resolve 'core-js/modules/es6.array.map' in source directory
17,994
Try to add the following in your resolve
s -
resolve: {
extensions: [
'.ts',
'.js' // add this
]
}
Author by
legogo
Updated on June 09, 2022Comments
-
legogo almost 2 years
I'm facing this error when I execute
webpack
:Module not found: Error: Can't resolve 'core-js/modules/es6.array.map' in '/path/to/project/src' @ ./src/index.ts 1:0-39
index.ts
:console.log([1, 2, 3].map(x => x * x));
.babelrc
:{ "presets": [ [ "@babel/preset-env", { "useBuiltIns": "usage" } ] ] }
webpack.config.js
:const path = require('path'); module.exports = { mode: 'development', entry: './src/index.ts', devtool: false, output: { filename: 'bundle.js', path: path.join(__dirname, 'dist') }, module: { rules: [ { test: /\.ts$/, use: [ { loader: 'babel-loader' }, { loader: 'ts-loader' } ] } ] }, resolve: { extensions: [ '.ts' ] } };
I think it's very weird that the error is trying to resolve the module in
src/
, notnode_modules/
.I tried removing
node_modules
andpackage.json
and thennpm i
, but it didn't change the situation.I also tried another way to use
@babel/polyfill
described here.Setting
useBuiltIns
to'entry'
just increased the number of similar errors. Setting it tofalse
caused different errors.Module not found: Error: Can't resolve 'core-js/es6' in '/path/to/project/node_modules/@babel/polyfill/lib' @ ./node_modules/@babel/polyfill/lib/index.js 3:0-22 @ multi @babel/polyfill ./src/index.ts ERROR in ./node_modules/@babel/polyfill/lib/index.js Module not found: Error: Can't resolve 'regenerator-runtime/runtime' in '/path/to/project/node_modules/@babel/polyfill/lib' @ ./node_modules/@babel/polyfill/lib/index.js 23:0-38 @ multi @babel/polyfill ./src/index.ts
It seems
core-js
andregenerator-runtime
should be installed innode_modules/@babel/polyfill/
. Currently, there are onlyindex.js
andnoConflict.js
in the directory. Do I have to manually install those modules in this directory?