gpt4 book ai didi

webpack - Babel 不接受选项

转载 作者:行者123 更新时间:2023-12-02 15:56:34 28 4
gpt4 key购买 nike

webpack.config.js:

module.exports = {
entry: __dirname + '/src/app.js',
output: {
path: __dirname + '/dist',
filename: 'test.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['env', {
targets: {
chrome: 52
}
}]
}
}
}
]
}
};

看似简单,实则抛出错误

Module build failed: ReferenceError: [BABEL] /src/app.js: Unknown option: foreign.targets. Check out http://babeljs.io/docs/usage/options/ for more information about options.

这没有任何意义。错误是由“env”预设的选项触发的。知道为什么 babel preset 突然不接受选项吗?

最佳答案

想通了。预设选项应位于嵌套数组中,因此正确的选项列表应如下所示:

                options: {
presets: [
['env', {
targets: {
chrome: 52
}
}]
]
}

关于webpack - Babel 不接受选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47370245/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com