Tag Archives: Support for the experimental syntax ‘decoratorslegacy’ isn’t currently enabled

[Solved] react Project Error: Support for the experimental syntax ‘decorators-legacy’ isn’t currently enabled

The write method of high-level component decorator is used in react project, and then the project reports an error. The information is as follows:

Support for the experimental syntax ‘decorators-legacy’ isn’t currently enabled

 

Solution:

1. Install Babel plugin transform decorators legacy

yarn add babel-plugin-transform-decorators-legacy

2. Modify the configuration file, package Add the following code to JSON:

"plugins": [

["@babel/plugin-proposal-decorators", { "legacy": true }]],

Package There is no Babel configuration in JSON, which needs to be executed

yarn eject

Display the configuration of react script that is not displayed in package JSON

If the console reports an error after execution, the solution is to submit the local modification and execute

git add
git commit -m ''

Then execute the yarn eject

3. Install Babel plugin transform decorators legacy

4. Modify package Babel in JSON

"babel": {

"plugins": [

["@babel/plugin-proposal-decorators", { "legacy": true }]

],

"presets": [

"react-app"

]}