問(wèn)題
Error: The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean. If you are migrating from Babylon/Babel 6 or want to use the old decorators proposal, you should use the 'decorators-legacy' plugin instead of 'decorators'.
解釋
“decorators”插件需要一個(gè)“decoratorsBeforeExport”選項(xiàng),其值必須是布爾值。如果您正在從Babylon/Babel 6 遷移過(guò)來(lái),或者想使用舊的decorator,您應(yīng)該使用“decorator -legacy”插件而不是“decorator”。
最開(kāi)始我想使用rudex的裝飾器connect,然后搜了一下博客
第一步:安裝babel-plugin-transform-decorators-legacy插件
cnpm install babel-plugin-transform-decorators-legacy
第二步:進(jìn)行配置
npm run eject
在package.json找到
"babel": {
"presets": [
"react-app"
],
}
在里面添加:
"babel": {
"presets": [
"react-app"
],
"plugins": [
"transform-decorators-legacy"
]
}
結(jié)果報(bào)錯(cuò)
Error: The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean. If you are migrating from Babylon/Babel 6 or want to use the old decorators proposal, you should use the 'decorators-legacy' plugin instead of 'decorators'.
繼續(xù)尋找解決方法:
安裝:
cnpm install @babel/plugin-proposal-decorators --save-dev
配置:
"babel": {
"presets": [
"react-app"
],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose" : true }]
]
}
}
問(wèn)題解決
如果用的是vscode有提示報(bào)錯(cuò) “experimentalDecorators”
在項(xiàng)目根目錄下添加jsconfig.json文件
{
"compilerOptions": {
"experimentalDecorators": true
}
}