javascript “npm-run-all”不被识别为内部或外部命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54525742/
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
"npm-run-all" Is Not Recognized As an Internal or External Command
提问by topreddy
I installed npm-run-all and also configured the environment variable (which may or may not be not required) on my Windows machine but am getting an error:
我在 Windows 机器上安装了 npm-run-all 并配置了环境变量(可能不需要也可能不需要),但出现错误:
'npm-run-all' is not recognized as an internal or external command, operable program or batch file
“npm-run-all”不是内部或外部命令,也不是可运行的程序或批处理文件
I am trying to build my current project with npm run buildwhich includes the script where the error is thrown:
我正在尝试构建我当前的项目,npm run build其中包含引发错误的脚本:
npm-run-all -p build-css build-webpack
Do I have to do any additional things to make it run?
我是否必须执行任何其他操作才能使其运行?
回答by David
You may just need to run the following command first (from the directory with the package.json file)
您可能只需要首先运行以下命令(从包含 package.json 文件的目录中)
npm install
回答by Matt Holland
You have a couple of options here, besides installing npm-run-allas a global package as suggested by @Vaibhav in the comments:
除了npm-run-all按照@Vaibhav 在评论中的建议安装为全局包之外,您还有几个选择:
1) Create an NPM script
1) 创建NPM 脚本
The package.jsonfile has a scriptssection which can used to define shortcuts for anything you need to run while you're working on your app. There are some pre-defined scripts, like runor testthan can be executed with simply npm start/npm testor you can define anything you like and then run it with npm run my-script-name. You could try:
该package.json文件有一个scripts部分,可用于为您在处理应用程序时需要运行的任何内容定义快捷方式。有一些预定义的脚本,比如run或test比可以简单地执行npm start/npm test或者你可以定义任何你喜欢的东西,然后用npm run my-script-name. 你可以试试:
{
"scripts": {
"start": "npm-run-all -p build-css build-webpack"
}
}
Any NPM module referenced here "just works" (i.e. the path to the executable is resolved under the hood by NPM)
此处引用的任何 NPM 模块都“正常工作”(即,可执行文件的路径由 NPM 在后台解析)
2) NPX
2)NPX
In newer versions of NPM (i.e. >= 5.2 or so), the "NPX" executable is provided. This has a similar effect to running commands inside an NPM script. You would run:
在较新版本的 NPM(即 >= 5.2 左右)中,提供了“NPX”可执行文件。这与在 NPM 脚本中运行命令的效果类似。你会运行:
npx npm-run-all -p build-css build-webpack
Again, the path would be automatically resolved.
同样,路径将自动解析。
If you have an older NPM install, you can also install it separately:
如果您安装了较旧的 NPM,也可以单独安装:
npm install -g npx
回答by Jojo Tutor
- Make sure the
npm-run-allis in your package.jsondevDependencies. - If
npm-run-allis present in your package.json, runnpm i - If not present install it, run:
npm i npm-run-all -D
- 确保
npm-run-all在您的 package.json 中devDependencies。 - 如果
npm-run-all存在于您的 package.json 中,请运行npm i - 如果不存在安装它,运行:
npm i npm-run-all -D
If error is still present, follow these steps:
如果错误仍然存在,请按照下列步骤操作:
- Remove node_modules folder: run
rm -rf node_modules - Install all dependecies: run
npm i
- 删除 node_modules 文件夹:运行
rm -rf node_modules - 安装所有依赖:运行
npm i
Hope this helps!
希望这可以帮助!
回答by Salomon Zhang
I had same problem while using code editor Brackets.
我在使用代码编辑器 Brackets 时遇到了同样的问题。
To resolve the error, I did the following steps.
为了解决该错误,我执行了以下步骤。
Add nodejs new system variable to your PC under Control Panel -> System -> Advanced System Settings
在控制面板 -> 系统 -> 高级系统设置下将 nodejs 新系统变量添加到您的 PC
;C:\Program Files\nodejs\
After that, re-run command:
之后,重新运行命令:
npm
回答by kp1
I don't know if this would help anyone, but I got this error because I was doing nodemon server.js instead of nodemon server/server.js. I wasn't in the right folder!
我不知道这是否对任何人有帮助,但我收到此错误是因为我正在执行 nodemon server.js 而不是 nodemon server/server.js。我不在正确的文件夹中!
回答by Ram
Did you reopen the terminal after you installed node?
安装节点后是否重新打开终端?
If you have installed npm with the current terminal window open. Your terminal window will not have loaded the latest path settings (with npm location) to find the npm application to run the command. In this case try below steps .
如果您在当前终端窗口打开的情况下安装了 npm。您的终端窗口将不会加载最新的路径设置(带有 npm 位置)来查找 npm 应用程序来运行命令。在这种情况下,请尝试以下步骤。
- Try closing the current terminal session.
- Reopen a new session.
- Try the command again ( will pick up the new path settings with npm installed)
- 尝试关闭当前终端会话。
- 重新打开一个新会话。
- 再次尝试该命令(将选择安装了 npm 的新路径设置)

