【发布时间】:2020-07-08 11:25:27
【问题描述】:
运行 webpack 我收到错误:
ERROR in ./node_modules/core-js/index.js
Module not found: Error: Can't resolve './es' in 'pathtoproject\node_modules\core-js'
@ ./node_modules/core-js/index.js 1:0-15
@ multi core-js whatwg-fetch ./src/contactForm.tsx
ERROR in ./node_modules/core-js/index.js
Module not found: Error: Can't resolve './internals/path' in 'pathtoproject\node_modules\core-js'
@ ./node_modules/core-js/index.js 4:11-38
@ multi core-js whatwg-fetch ./src/contactForm.tsx
ERROR in ./node_modules/core-js/index.js
Module not found: Error: Can't resolve './proposals' in 'pathtoproject\node_modules\core-js'
@ ./node_modules/core-js/index.js 2:0-22
@ multi core-js whatwg-fetch ./src/contactForm.tsx
ERROR in ./node_modules/core-js/index.js
Module not found: Error: Can't resolve './web' in 'pathtoproject\node_modules\core-js'
@ ./node_modules/core-js/index.js 3:0-16
@ multi core-js whatwg-fetch ./src/contactForm.tsx
这些文件夹确实存在。我相信这与 Windows 路径有关,因为当我将 core-js/index.js 文件更改为使用 path.resolve() 而不是相对导入时,它确实有效。这不是我想要的解决方案,因为它需要更改 core-js 模块。
参考这里是我的 webpack.config.js
const path = require('path');
module.exports = {
entry: ["core-js", "whatwg-fetch", "./src/contactForm.tsx"],
output: {
path: path.join(__dirname, "build/assets/js/"),
filename: "contactForm.js"
},
mode: "production",
// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx"]
},
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader"
}
]
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
enforce: "pre",
test: /\.js$/,
loader: "source-map-loader"
}
]
},
// When importing a module whose path matches one of the following, just
// assume a corresponding global variable exists and use that instead.
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
externals: {
"react": "React",
"react-dom": "ReactDOM"
}
};
任何修复的想法将不胜感激
【问题讨论】:
标签: javascript node.js typescript webpack core-js