在编写个人博客的时候莫名其妙遇到了如下问题:
Module build failed (from ./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib/index.js):
SyntaxError: D:\VSCODE\building\project_all_1.1\project1.1\node_modules\marked\lib\marked.esm.js: Class private methods are not enabled. Please add `@babel/plugin-transform-private-methods` to your configuration.
在网上搜了很多答案,能了解到是babel配置问题,因此又使用了一些方法。
最初我以为是因为marked模块导入方式的不正确或者是模块其他的问题,最后我简单修改了脚手架中的babel.config.js才最终消除报错,修改之后的配置如下:
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
],
plugins: [
["@babel/plugin-transform-private-methods",{"loose":true}],
["@babel/plugin-transform-class-properties", {
"loose": true
}],
["@babel/plugin-transform-private-property-in-object", {
"loose": true
}]
]
}
我也不是很懂具体的配置信息,主要是修改了其中的loose:true属性,最终才消除了问题。