gpt4 book ai didi

reactjs - React 脚本启动给出了 Unexpected token 错误

转载 作者:行者123 更新时间:2023-12-04 01:08:55 26 4
gpt4 key购买 nike

我一直在使用create-react-app一直在引导 react 应用程序。
但我今天面临一个非常奇怪的问题。
使用 create-react-app 引导我的应用程序后.运行 npm start 后,我面临以下问题

rbac-tutorial-app/node_modules/@hapi/joi/lib/types/object/index.js:254
!pattern.schema._validate(key, state, { ...options, abortEarly:true }).errors) {
^^^

SyntaxError: Unexpected token ...
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (rbac-tutorial-app/node_modules/@hapi/joi/lib/types/func/index.js:5:20)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! rbac-tutorial-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the rbac-tutorial-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我已经试过了
- 删除 package.lock.json 并删除节点模块并运行 npm install后跟 npm start但问题仍然存在。
- 更改我的节点和 npm 版本。

我正在使用的 NPM 版本 -> 6.9.0我正在使用的节点版本 -> v8.0.0
以下是我的 package.json文件
{
"name": "rbac-tutorial-app",
"version": "0.1.0",
"private": true,
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1"
},
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-router": "^5.0.0",
"react-router-dom": "^5.0.0",
"react-scripts": "3.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

任何帮助将不胜感激。

最佳答案

经过几个令人沮丧的小时寻找答案并尝试不同的方法后,我认为这不是我的代码的问题,而是使用 create-react-app 引导时出现的问题。使用 node version v8.0.0 .

所以我删除了整个项目并按照以下步骤解决了我的问题 -

  • 删除了整个项目。由于到目前为止我还没有写太多代码,所以我只是这样做了。如果你已经写了很多代码,请备份。
  • 我安装了NVM(Node Version Manager) .我用这个链接How to install NVM in Ubuntu安装相同。
  • 安装 nvm 后,使用 nvm install 12.0.0(or the node version > 8.0.0 which you would like to use) .这实际上是我的问题。对于 create-react-app要成功引导,您应该使用 node version > 8.0.0 .
  • 之后我使用 nvm use 12.0.0(or the node version which you have recently installed) .
  • 使用 node -v 检查您的节点版本.它应该显示您在步骤 4 中要求使用的节点版本。
  • 就是这样。现在你应该使用 create-react-app并再次引导应用程序。

  • 这对我来说就像一个魅力。希望遇到同样问题的人会发现它有帮助。

    关于reactjs - React 脚本启动给出了 Unexpected token 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56110924/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com