typescript webpack 和 babel-polyfill:无法解析源目录中的“core-js/modules/es6.array.map”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54869212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
webpack & babel-polyfill: Can't resolve 'core-js/modules/es6.array.map' in source directory
提问by legogo
I'm facing this error when I execute webpack
:
我在执行时遇到此错误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
:
index.ts
:
console.log([1, 2, 3].map(x => x * x));
.babelrc
:
.babelrc
:
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage"
}
]
]
}
webpack.config.js
:
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/
, not node_modules/
.
我认为错误试图解决模块中的模块非常奇怪,而src/
不是node_modules/
.
I tried removing node_modules
and package.json
and then npm i
, but it didn't change the situation.
我尝试删除node_modules
and package.json
then npm i
,但它没有改变情况。
I also tried another way to use @babel/polyfill
described here.
我还尝试了另一种使用方式@babel/polyfill
描述here。
Setting useBuiltIns
to 'entry'
just increased the number of similar errors. Setting it to false
caused different errors.
设置useBuiltIns
为'entry'
只是增加了类似错误的数量。将其设置为false
导致不同的错误。
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
and regenerator-runtime
should be installed in node_modules/@babel/polyfill/
. Currently, there are only index.js
and noConflict.js
in the directory. Do I have to manually install those modules in this directory?
似乎core-js
并且regenerator-runtime
应该安装在node_modules/@babel/polyfill/
. 目前,目录中只有index.js
和noConflict.js
。我是否必须在此目录中手动安装这些模块?
采纳答案by legogo
Try to add the following in your resolve
s -
尝试在您的resolve
s 中添加以下内容-
resolve: {
extensions: [
'.ts',
'.js' // add this
]
}