我正在尝试将@ babel / preset-polyfill与webpack 4一起使用,如下所示:
const HtmlWebPackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-react", "@babel/polyfill"]
}
}
},
{
test: /\.html$/,
use: [{
loader: "html-loader",
options: {
minimize: true
}
}]
},
{
test: /\.scss$/,
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"]
}
]
},
plugins: [
new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html"
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css"
})
]
};
编译器抱怨:
ERROR in ./src/index.js Module build failed: Error: Cannot find module '@babel/preset-polyfill' from '/Volumes/Develop/html/ReactReasonTemplate'
- If you want to resolve "@babel/polyfill", use "module:@babel/polyfill"
at Function.module.exports [as sync] (/Volumes/Develop/html/ReactReasonTemplate/node_modules/resolve/lib/sync.js:42:15)
at resolveStandardizedName (/Volumes/Develop/html/ReactReasonTemplate/node_modules/@babel/core/lib/config/files/plugins.js:100:31)
at resolvePreset (/Volumes/Develop/html/ReactReasonTemplate/node_modules/@babel/core/lib/config/files/plugins.js:57:10)
at loadPreset (/Volumes/Develop/html/ReactReasonTemplate/node_modules/@babel/core/lib/config/files/plugins.js:76:20)
at createDescriptor (/Volumes/Develop/html/ReactReasonTemplate/node_modules/@babel/core/lib/config/config-descriptors.js:135:21)
at items.map (/Volumes/Develop/html/ReactReasonTemplate/node_modules/@babel/core/lib/config/config-descriptors.js:87:50)
at Array.map (<anonymous>)
at createDescriptors (/Volumes/Develop/html/ReactReasonTemplate/node_modules/@babel/core/lib/config/config-descriptors.js:87:29)
at createPresetDescriptors (/Volumes/Develop/html/ReactReasonTemplate/node_modules/@babel/core/lib/config/config-descriptors.js:79:10)
at passPerPreset (/Volumes/Develop/html/ReactReasonTemplate/node_modules/@babel/core/lib/config/config-descriptors.js:71:96) @ multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.js .
我做错了什么?
答案 0 :(得分:0)
从.babelrc文件中的“预设”中删除“ @ babel / preset-polyfill”后为我工作