react 使用rewired_react-app-rewired start启动react项目报错

孟成化
2023-12-01

问题描述

D:\client>yarn start

yarn run v1.12.3

$ react-app-rewired start

D:\client\config-overrides.js:3

config = injectBabelPlugin(["@babel/plugin-proposal-decorators", { legacy: true }], config);

^^^^^^

SyntaxError: Rest parameter may not have a default initializer

at new Script (vm.js:79:7)

at createScript (vm.js:251:10)

at Object.runInThisContext (vm.js:303:10)

at Module._compile (internal/modules/cjs/loader.js:656:28)

at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)

at Module.load (internal/modules/cjs/loader.js:598:32)

at tryModuleLoad (internal/modules/cjs/loader.js:537:12)

at Function.Module._load (internal/modules/cjs/loader.js:529:3)

at Module.require (internal/modules/cjs/loader.js:636:17)

at require (internal/modules/cjs/helpers.js:20:18)

error Command failed with exit code 1.

info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

### 问题出现的环境背景及自己尝试过哪些方法

一开始运行的时候是出现这个错误D:\client\src\component\Login.js: Support for the experimental syntax 'decorators-legacy' isn't currently enabled (14:5)

安装了mobx及mobx-react然后将config-overrides.js改成

module.exports = function override(config, env) {

...

config = injectBabelPlugin(["@babel/plugin-proposal-decorators", { legacy: true }], config);

return config;

}

之后就出现问题描述的错误

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

config-overrides.js配置为

module.exports = function override(config, env) {

...

config = injectBabelPlugin(["@babel/plugin-proposal-decorators", { legacy: true }], config);

return config;

}

package.json配置为

{

"name": "client",

"version": "0.1.0",

"private": true,

"dependencies": {

"bootstrap": "^4.1.3",

"jquery": "^3.3.1",

"mobx": "^5.8.0",

"mobx-react": "^5.4.3",

"react": "^16.6.3",

"react-dom": "^16.6.3",

"react-router-dom": "^4.3.1",

"react-scripts": "2.1.1",

"reactstrap": "^6.5.0"

},

"scripts": {

"start": "react-app-rewired start",

"build": "react-app-rewired build",

"test": "react-app-rewired test --env=jsdom",

"eject": "react-scripts eject"

},

"eslintConfig": {

"extends": "react-app"

},

"browserslist": [

">0.2%",

"not dead",

"not ie <= 11",

"not op_mini all"

],

"devDependencies": {

"react-app-rewire-mobx": "^1.0.9",

"react-app-rewired": "^1.6.2"

}

}

你期待的结果是什么?实际看到的错误信息又是什么?

希望成功运行react项目

 类似资料: