简体   繁体   English

如何解决 sh: react-scripts: command not found?

[英]How to resolve sh: react-scripts: command not found?

I used create-react-app to generate an app.我使用 create-react-app 来生成一个应用程序。

create-react-app myapp

When I run yarn start or npm start I get this error:当我运行 yarn start 或 npm start 时,出现此错误:

react-scripts start反应脚本开始

sh: react-scripts: command not found npm ERR! sh:react-scripts:找不到命令 npm ERR! file sh npm ERR!文件 sh npm 错误! code ELIFECYCLE npm ERR!代码 ELIFECYCLE npm ERR! errno ENOENT npm ERR! errno ENOENT npm 错误! syscall spawn npm ERR!系统调用产生 npm ERR! myapp@0.1.0 start: react-scripts start npm ERR! myapp@0.1.0 开始: react-scripts start npm ERR! spawn ENOENT npm ERR!生成 ENOENT npm ERR! npm ERR! npm 错误! Failed at the myapp@0.1.0 start script.在 myapp@0.1.0 启动脚本中失败。 npm ERR! npm 错误! This is probably not a problem with npm.这可能不是 npm 的问题。 There is likely additional logging output above.上面可能有额外的日志输出。

When I run npm ls react:当我运行 npm ls 时反应:

myapp@0.1.0 /Users/johnno/foosball 
└── react@16.2.0

react-scripts is present.反应脚本存在。

This is my package.json:这是我的 package.json:

{
  "name": "myapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-redux": "^5.0.6",
    "react-router": "^4.2.0",
    "react-scripts": "1.0.17",
    "redux": "^3.7.2",
    "yarn": "^1.3.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

I tried the suggestions from this but to no avail.我尝试了this的建议,但无济于事。 How can I fix this issue?我该如何解决这个问题?

i solved this by deleting 我通过删除解决了这个问题

node_modules node_modules
yarn.lock 纱锁
manifest_lock.json manifest_lock.json

and installed packages by 和安装的软件包

npm install

or 要么

yarn

Following steps worked for me以下步骤对我有用

  1. delete node_modules folder删除node_modules文件夹
  2. delete yarn.lock if you are using yarn command or delete package-lock.json if you are using npm command删除yarn.lock如果您正在使用yarn命令或删除package-lock.json如果您正在使用npm命令
  3. run yarn install (for yarn command) or npm install (for npm command)运行yarn install (对于 yarn 命令)或npm install (对于 npm 命令)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM