react-scripts' 不被识别为内部或外部命令

wij*_*Men 8 npm reactjs

我遵循 udemy 课程,使用create-react-app,然后使用npm start. 它工作正常,直到我安装react-router-dom然后我在终端中收到此错误:

react-scripts' is not recognized as an internal or external command, operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! venue@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the venue@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下这是怎么回事吗?以及如何修复它?

谢谢

小智 12

有一些问题npm install无法完成 React 脚本的安装。按照这些简单的步骤来让它工作。

  1. 删除 node_modules 文件夹
  2. 删除 package-lock.json 文件
  3. npm install
  4. npm i -S react-scripts
  5. npm start

它现在应该可以工作了。


jus*_*ird 5

我注意到,如果您频繁切换软件包的版本,就会出现此问题。主要是缓存问题。并通过执行以下步骤解决:

  1. 删除node_modules目录,以便我们获得软件包的新副本
  2. 删除package-lock.jsonyarn.lock
  3. 现在清除缓存,我们需要npm cache clean --force在终端中运行命令。PS: clean --> 删除本地缓存文件夹中的所有数据
  4. 运行npm iyarn
  5. 现在,如果您运行脚本,它应该可以工作。