繁体   English   中英

反应脚本:找不到命令

[英]react-scripts: command not found

我目前正在尝试使用 create-react-app,它使用三个不同的包:react、react-scripts 和 react-dom。 我已经安装了 create-react-app ,然后当我切换到目录并点击npm start我得到一个react-scripts: command not found 我遇到了很多问题。 我可以看到react-scripts在我的node_modules文件夹中,但是在尝试运行npm start时我不断收到command not found 我试图删除并重新安装我所有的node_modules但它没有用。 还有谁有相同的问题吗?

 ✘ ✝  Node/toDoApp/my-test   master±  npm start

> my-test@0.1.0 start /Users/jzilch/Desktop/Web 
Projects/Node:Express/Node/toDoApp/my-test
> react-scripts start

sh: react-scripts: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! my-test@0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the my-test@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely 
additional logging output above.

首先删除项目文件夹中的package-lock.json文件。

然后通过npm install再次安装依赖项。 那应该可以解决这个问题。

这通常是因为 npm 包安装错误(同时使用 npm 和 yarn?)。 这可能令人绝望,但如果您尝试这些步骤,它应该会奏效。

第一个解决方案:

删除node_modules文件夹。 在项目的根文件夹中,运行

> yarn
> yarn run start

第二种解决方案:

在项目的根文件夹中,运行

> yarn upgrade
> yarn
> yarn run start

下次您想使用 create-react-app 添加依赖项时,我建议您使用“yarn add”而不是“npm install”。 (来源: https : //github.com/facebook/create-react-app/issues/1155

使用rm命令删除/node_modules目录和package-lock.json文件:

rm -rf node_modules
rm -f package-lock.json

使用以下命令安装 react-scripts:

npm install react-scripts

使用以下命令安装依赖项:

npm install

通过运行以下命令启动本地服务器:

npm run start

注意:如果您是 Linux 用户,请不要忘记在npm之前添加sudo命令。

我在 dockerizer 环境中使用它。 我已经使用package.json在 node_modules 中本地安装。

所以,我添加了这个:

RUN npm install -g react-scripts
RUN npm install

这解决了我令人困惑的问题

当我使用yarn ,我不得不运行yarn add react-scripts

我有这个问题很久了,我最终偶然找到了我的解决方案。
事实证明,任何文件夹名称中都不能有空格

例如~/projects/tutorial/ReactJS/JavaScript Framework: ReactJS/app-name将不起作用,因为JavaScript Framework: ReactJS包含空格。
一般来说,无论如何在文件夹/文件名中使用空格可能不是很好的做法,但我希望这可以为某人节省至少 4 小时的试错时间。

我建议也删除:从您的文件夹名称中删除! (只是为了安全)

一种选择是使用-g标志全局安装react-scripts包。 这将使命令可用于节点,而不管工作目录如何。

此命令将全局安装react-scripts

npm install -g react-scripts

我也遇到过这个问题。要解决这个问题,删除你的

节点模块
纱线锁
manifest_lock.json

它有效。

我通过更改本地系统中的文件夹名称来修复它,从

new/landing

new_landing

但是,git 分支名称仍然像“new/landing”。 我的 MAC 系统就是这种情况。

对我来说,我删除了该项目并使用npm create-react-app <Folder Name>脚本初始化了另一个项目。 而不是create-react-app <Folder Name> 它对我有用。

暂无
暂无

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

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