Vue.js 错误:TypeError: Cannot set property 'presets' of undefined - 解决方法
这个错误是因为在 vue.config.js 文件中的 chainWebpack 方法中尝试设置 presets 属性,但是此时 presets 对象未定义。解决方法是确保 presets 对象已经定义并且安装了相关的插件。
例如,如果你想使用 babel-preset-env,可以在项目中安装它:
npm install babel-preset-env --save-dev
然后在 vue.config.js 文件中使用:
module.exports = {
chainWebpack: config => {
config.module
.rule('js')
.use('babel-loader')
.loader('babel-loader')
.tap(options => {
options.presets = ['@babel/preset-env']
return options
})
}
}
原文地址: https://www.cveoy.top/t/topic/otPi 著作权归作者所有。请勿转载和采集!