裝飾器connect問(wèn)題:Error: The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose val...

問(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

  }

}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容