reactjs - sh : react-scripts: command not found

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

我正在上 Udemy 的类(class),我们将在其中使用 create-react-app。但是当我开始运行 npm start 和/或 yarn start 时,我得到一个错误。

这是类(class):Complete React Developer in 2020 (w: Redux, Hooks, GraphQL)

npx create-react-app test-npm(如果我使用 npm,则使用 --use-npm)

我们建议您先输入:

光盘测试
npm 开始

祝你黑客愉快!
➜ 2020 年完成 React Developer (w: 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

yarn 结果:

➜  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。但是我发现的所有提示都没有用。

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

最佳答案

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

例如 user/project 1/react //This cause the error. user/project1/react //这没问题

关于reactjs - sh : react-scripts: command not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59880135/

相关文章:

javascript - 具有多个setstate的React js单个函数

reactjs - 将服务器端渲染添加到 create-react-app

reactjs - Create-react-app 服务工作人员无法正常工作

javascript - GraphQL 使用字段值作为另一个查询的变量

javascript - 在 React 中,数字输入是字符串而不是整数

javascript - react.js firebase 返回一个处于错误状态的响应对象

javascript - 打包flow中编写的npm项目

node.js - 套接字 (10106) 错误 Node

macos - 任何命令的 NPM 错误

reactjs - 将分页与react-bootstrap表一起使用