npm start 在 WebStorm 上的 React 应用程序中产生错误

npm start produces error in React app on WebStorm

我看到之前有人问过这个问题,但是 none 的解决方案似乎对我有帮助。

我遇到错误,我也尝试删除 node_modules 目录。然后重新安装 npm。还是一样的错误。

  1. rm -rf node_modules
  2. npm install
  3. npm start -- 同样的错误

甚至尝试删除 package-lock.json,但 npm start 出现同样的错误。

节点版本 - v10.15.3
NPM 版本 - 6.4.1

Aryans-MacBook-Pro:react-new-app aryanarora$ npm start

> react-new-app@0.1.0 start /Users/aryanarora/Desktop/The Web Developer Bootcamp/01 All Practice Files /js<:>/Jon Duckett/react-new-app
> react-scripts start

sh: react-scripts: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! react-new-app@0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the react-new-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/aryanarora/.npm/_logs/2019-04-29T06_08_07_273Z-debug.log

完成后npm list --depth 0 | grep react-scripts 输出如下:

Aryans-MacBook-Pro:react-new-app aryanarora$ npm list --depth 0 | grep react-scripts
└── react-scripts@3.0.0
npm ERR! peer dep missing: typescript@*, required by @typescript-eslint/eslint-plugin@1.6.0
npm ERR! peer dep missing: typescript@*, required by @typescript-eslint/parser@1.6.0
npm ERR! peer dep missing: typescript@*, required by @typescript-eslint/parser@1.6.0
npm ERR! peer dep missing: typescript@*, required by @typescript-eslint/typescript-estree@1.6.0
npm ERR! peer dep missing: typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev, required by tsutils@3.10.0
npm ERR! peer dep missing: typescript@*, required by @typescript-eslint/typescript-estree@1.6.0
npm ERR! peer dep missing: typescript@*, required by ts-pnp@1.1.2

Package.json 文件

{
  "name": "react-new-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts": "3.0.0"
  },
  "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"
    ]
  }
}

请确保安装了 React-scripts 节点模块,要检查这一点,请执行以下步骤。

  • 再次安装 npm install
  • 转到 node_modules --> react-scripts(确保文件夹存在)
  • 运行 npm start

可能是npm版本问题。请尝试一些建议。

  1. 卸载 yarn npm uninstall -g yarn

  2. 清理缓存。 npm cache clean -f

  3. 如果还是不行,尝试downgrade/upgrade你的npm版本到npm 5.4.2或npm 5.3.*.

    npm install -g npm@5.4.2

问题可能出在节点和 npm 本身。 尝试使用 Homebrew 或 NVM 从您的机器上完全卸载节点,无论您使用哪个来安装节点。否则你必须手动完成。

按照此 link - https://stackabuse.com/how-to-uninstall-node-js-from-mac-osx/

中的步骤操作

接下来从官方网站安装 LTS 节点 (https://nodejs.org/en/),这应该可以解决问题。

我还发现有帮助的一件事是更改目录。我的目录中有一个名为“</>js”的文件夹,我认为它造成了一些问题。