无法运行React项目,因为出现了react-scripts错误。

huangapple go评论61阅读模式
英文:

Can't run React project due to react-scripts error

问题

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.6",
    "@testing-library/react": "^11.2.1",
    "@testing-library/user-event": "^12.2.2",
    "axios": "^0.21.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-input-range": "^1.3.0",
    "react-redux": "^7.2.4",
    "react-router": "^5.2.1",
    "react-router-dom": "^5.2.1",
    "react-scripts": "^5.0.1",
    "redux": "^4.1.1",
    "redux-devtools-extension": "^2.13.9",
    "redux-thunk": "^2.3.0",
    "styled-components": "^5.3.1",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
英文:

I'm trying to start a React project with npm start and the following error is shown:

$ npm start

> client@0.1.0 start
> react-scripts

Unknown script "undefined".
Perhaps you need to update react-scripts?
See: https://facebook.github.io/create-react-app/docs/updating-to-new-releases

I have updated react-scripts to last version, npm install, even I pulled a version of the project without the previous changes and still the error is shown.

I share the package.json. I appreciate any help and suggestions in advance.

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.6",
    "@testing-library/react": "^11.2.1",
    "@testing-library/user-event": "^12.2.2",
    "axios": "^0.21.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-input-range": "^1.3.0",
    "react-redux": "^7.2.4",
    "react-router": "^5.2.1",
    "react-router-dom": "^5.2.1",
    "react-scripts": "^5.0.1",
    "redux": "^4.1.1",
    "redux-devtools-extension": "^2.13.9",
    "redux-thunk": "^2.3.0",
    "styled-components": "^5.3.1",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}```

</details>


# 答案1
**得分**: 2

 "react-scripts" 中添加 "start"
即:
"scripts": {
    "start": "react-scripts start",
  }

<details>
<summary>英文:</summary>

Add start to &quot;react-scripts&quot;.
i.e. 
&quot;scripts&quot;: {
    &quot;start&quot;: &quot;react-scripts start&quot;,
  }

</details>



# 答案2
**得分**: 0

使用 `npm run start`。

如果那不起作用,请尝试删除您的 `package-lock.json`  `node_modules` 文件夹,然后运行 `npm install`,然后再次尝试。

<details>
<summary>英文:</summary>

Use `npm run start`.

If that doesn&#39;t work, try removing your `package-lock.json` and `node_modules` folder, then run `npm install` and try again.

</details>



huangapple
  • 本文由 发表于 2023年2月19日 11:23:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497789.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定