【发布时间】: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