我克隆了一个react应用程序到我的系统上,并运行以下命令

npm install -g create-react-app
npm install --save react react-dom

之后我就跑了

npm start 

但是它抛出了上面提到的错误,它在我的其他系统上工作得很好,我把它推到了github上。但克隆后,无论是windows还是mac,它都不能在任何其他系统上工作。


当前回答

我一直都有这个问题,最后我偶然找到了解决方法。 事实证明,在任何文件夹名称中都不能有空格或古怪的字符。

如。 ~/projects/tutorial/ReactJS/JavaScript框架:ReactJS/app-name 不会工作,因为JavaScript框架:ReactJS包含空格。 一般来说,在文件夹/文件名中使用空格可能不是很好的实践,但我希望这可以为某人节省至少4个小时的试验和错误。

此外,应该避免使用任何非字母数字字符。

其他回答

删除package-lock。json文件 删除“node_modules”文件夹 Sudo NPM I -force 输入您的笔记本电脑登录密码(如果被询问) 等待node_modules安装完成 npm开始

这个变通办法对我很管用

// in your package.json replace 
"start": "react-scripts start"

// with:
"start": "node_modules/react-scripts/bin/react-scripts.js start"

如果上面的解决方案不工作,你看到下面的错误:

npm ERR! The operation was rejected by your operating system.

npm ERR! It is likely you do not have the permissions to access this file as the current user

尝试用sudo NPM安装

在启动react项目之前运行npm i

你不应该在全局安装反应脚本,对我来说这解决了问题:

npm install --save react react-dom react-scripts

如果这仍然不工作:

更新到最新的NPM版本:NPM install -g npm@latest 删除“node_modules”目录 重新安装所有依赖项:NPM install