【问题标题】:sh: react-scripts: command not foundsh:反应脚本:找不到命令
【发布时间】:2023-03-02 21:28:02
【问题描述】:

我正在学习关于 Udemy 的课程,我们将使用 create-react-app。但是当我运行npm start 和/或yarn start 时,我得到了一个错误。

这是课程:Complete React Developer in 2020 (w: Redux, Hooks, GraphQL)

npx create-react-app test-npm(以及 --use-npm,如果我使用的是 npm)

我们建议您首先输入:

cd 测试
npm 开始

黑客愉快!
➜ 2020 年完成 React 开发人员(包括 Redux、Hooks、GraphQL)cd test
➜ test-npm git:(master) npm 或 yarn start

test-npm@0.1.0 start /Users/user/Udemy/Complete React Developer in 2020 (w: Redux, Hooks, GraphQL)/test
react-scripts start

npm 的结果:

sh: react-scripts: command not found  
npm ERR! code ELIFECYCLE  
npm ERR! syscall spawn  
npm ERR! file sh  
npm ERR! errno ENOENT  
npm ERR! test@0.1.0 start: `react-scripts start`  
npm ERR! spawn ENOENT     
npm ERR!  
npm ERR! Failed at the test-npm@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/user/.npm/_logs/2020-01-23T18_09_30_919Z-debug.log

纱线结果:

➜  test-yarn git:(master) yarn start  
yarn run v1.21.1  
$ react-scripts start  
/bin/sh: react-scripts: command not found  
error Command failed with exit code 127.  
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我在 mac(最新的 iOS)上,并使用 zsh 和 oh my zsh。

我的 .zshrc 文件:

(#) If you come from bash you might have to change your $PATH.  
(#) export PATH=$HOME/bin:/usr/local/bin:$PATH

(#)Path to your oh-my-zsh installation.  
export ZSH="/Users/mhagen/.oh-my-zsh"

ZSH_THEME="robbyrussell"

plugins=(git nvm)

source $ZSH/oh-my-zsh.sh

export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"

我的 .bash_profile 文件:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

我已经安装了:

➜  ~ nvm --version
0.35.2
➜  ~ node -v
v13.7.0
➜  ~ npm -v
6.13.6
➜  ~ yarn -v
1.21.1

我尝试删除 node_modules 和 package-lock/yarn 锁定文件,并使用 npm 和 yarn 安装它们(每次都删除项目和新文件)。

我尝试全局安装 create-react-app。但是我发现的任何提示都不起作用。

希望这里有人能看到我的问题:/

【问题讨论】:

  • 你的节点版本是多少?尝试在.zshrc顶部添加export PATH=$HOME/bin:/usr/local/bin:$PATH
  • export PATH=$HOME/bin:/usr/local/bin:$PATH 不起作用:/ 抱歉,这是我的第一个问题。谢谢你的cmets,希望这会更好:)

标签: reactjs npm create-react-app yarnpkg oh-my-zsh


【解决方案1】:

这是对我有用的解决方案:https://stackoverflow.com/a/59235436/10225590 您的项目路径中的任何文件夹的名称中都不能有空格。

例如 用户/项目 1/反应// This cause the error。 用户/project1/react // This is okay.

【讨论】:

  • 你是救生员。我不敢相信我在这上面浪费了这么多时间?
猜你喜欢
  • 2018-05-16
  • 1970-01-01
  • 2018-08-16
  • 2023-02-18
  • 2021-07-07
  • 2019-08-10
  • 2021-11-13
  • 2019-04-19
  • 2013-05-16
相关资源
最近更新 更多