Javascript 'react-scripts' 不被识别为内部或外部命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47928735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'react-scripts' is not recognized as an internal or external command
提问by J Smith
I've got a maven project, within which is JavaScript project cloned as a git sub-module. So the directory structure looks something like
我有一个 maven 项目,其中是作为 git 子模块克隆的 JavaScript 项目。所以目录结构看起来像
mavenapp/src/main/javascript/[npm project files]
mavenapp/src/main/javascript/[npm project files]
inside my package.json, the test looks like this : "test": "react-scripts test --env=jsdom",
在我的 package.json 中,测试如下所示: "test": "react-scripts test --env=jsdom",
but when I try to run npm test is says
但是当我尝试运行 npm test 时说
'react-scripts' is not recognized as an internal or external command,
'react-scripts' 不被识别为内部或外部命令,
Interestingly when I clone the javascript project independently I don't get this error. I've tried re-running npm install.
有趣的是,当我独立克隆 javascript 项目时,我没有收到此错误。我试过重新运行npm install。
npm version : 5.5.1
npm version : 5.5.1
node version : 9.3.0
node version : 9.3.0
回答by Yogesh Borad
It is an error about react-scriptsfile missing in your node modulesdirectory at the time of installation.
这是安装时节点模块目录中缺少react-scripts文件的错误。
Check your react-scriptdependency is avaliable or not in package.json
检查您的react-script依赖项在package.json 中是否可用
If not available then add manually via:
如果不可用,则通过以下方式手动添加:
npm install react-scripts --save
npm install react-scripts --save
回答by Jonny Asmar
Have you tried:
你有没有尝试过:
rm -rf node_modules && npm install
rm -rf node_modules && npm install
Wiping node_modulesfirst, often tends to fix a lot of weird, package related issues like that in Node.
node_modules首先擦除,通常往往会解决很多奇怪的,包相关的问题,比如 Node.js 中的那些问题。
回答by Hadi Mir
If react-scriptsis present in package.json
如果react-scripts存在于package.json
If you see something like this "react-scripts": "2.1.3"in your pakage.jsonfile then just type this command
如果您"react-scripts": "2.1.3"在pakage.json文件中看到类似的内容 , 则只需键入此命令
npm install
npm install
If react-scriptsis not present in package.json
如果react-scripts不在package.json
If there is nothing like "react-scripts"in your package.jsonfile then probably you have not installed it.To do that type the following command and you will be all set
如果"react-scripts"你的package.json文件中没有类似的东西,那么你可能还没有安装它。要做到这一点,请输入以下命令,你将全部设置好
npm install react-scripts --save
npm install react-scripts --save
回答by Nguyen Duc Thanh
In my situation, some problems happened with my node package. So I run npm audit fixand it fixed all problems
在我的情况下,我的节点包发生了一些问题。所以我跑了npm audit fix,它解决了所有问题
回答by Miraj Khandaker
I faced the same problem. But running the npm updatecommand it's solved my problem.
我遇到了同样的问题。但是运行npm update命令它解决了我的问题。
回答by Sandro Cagara
i fix this issue :-), just uninstall your node.js and show hidden files
我解决了这个问题:-),只需卸载你的 node.js 并显示隐藏文件
then go to "C:\Users\yourpcname\AppData\Roaming\
然后转到“C:\Users\yourpcname\AppData\Roaming\
then delete the "npm" and "npm-cache" folder
然后删除“npm”和“npm-cache”文件夹
and install a new version of node.js.
并安装新版本的 node.js。
回答by Ahmedakhtar11
react-scriptsis not recognized as an internal or external command is related to npm.
react-scripts未被识别为与 npm 相关的内部或外部命令。
I would update all of my dependencies in my package.json files to the latest versions in both the main directory and client directory if applicable. You can do this by using an asterisk "*" instead of specifying a specific version number in your package.json files for your dependencies.
如果适用,我会将我的 package.json 文件中的所有依赖项更新到主目录和客户端目录中的最新版本。您可以通过使用星号“*”而不是在 package.json 文件中为依赖项指定特定版本号来完成此操作。
For Example:
例如:
"dependencies": {
"body-parser": "*",
"express": "*",
"mongoose": "*",
"react": "*",
"react-dom": "*",
"react-final-form": "*",
"react-final-form-listeners": "*",
"react-mapbox-gl": "*",
"react-redux": "*",
"react-responsive-modal": "*",
}
I would then make sure any package-lock.json were deleted and then run npm install and yarn install in both the main directory and the client directory as well if applicable.
然后,我将确保删除所有 package-lock.json,然后在主目录和客户端目录中运行 npm install 和 yarn install(如果适用)。
You should then be able to run a yarn build and then use yarn start to run the application.
然后,您应该能够运行 yarn build,然后使用 yarn start 运行应用程序。
回答by Koder90
This is rather old question but this might be of some help for future reference. Delete node_modules folder and run npm install again. Worked for me.
这是一个相当古老的问题,但这可能对将来的参考有所帮助。删除 node_modules 文件夹并再次运行 npm install。为我工作。
回答by Tomá? Hübelbauer
I have tried many of the solutions to this problem found on line, but in my case nothing worked except for reinstalling NVM for Windows (which I am using to manage multiple Node versions). In the installer, it detects installed Node versions and asks the user if they wish for NVM to control them. I said yes and NVM fixed all PATH issues. As a result, things worked as before. This issue may have multiple causes, but corrupted PATH is definitely one of them and (re)installing NVM fixes PATH.
我已经尝试了许多在线找到的解决此问题的解决方案,但在我的情况下,除了重新安装 NVM for Windows(我用来管理多个 Node 版本)之外,没有任何效果。在安装程序中,它检测已安装的 Node 版本并询问用户是否希望 NVM 控制它们。我说是,NVM 修复了所有 PATH 问题。结果,事情和以前一样。此问题可能有多种原因,但损坏的 PATH 绝对是其中之一,并且(重新)安装 NVM 修复了 PATH。
回答by S. M. AMRAN
For Portable apps change
对于便携式应用程序更改
package.json
包.json
as follows
如下
"scripts": {
"start": "node node_modules/.bin/react-scripts start",
"build": "node node_modules/.bin/react-scripts build",
"test": "node node_modules/.bin/react-scripts test",
"eject": "node node_modules/.bin/react-scripts eject"
}

