简体   繁体   English

“npm-run-all”不被识别为内部或外部命令

[英]"npm-run-all" Is Not Recognized As an Internal or External Command

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 build which 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?我是否必须执行任何其他操作才能使其运行?

  1. Make sure the npm-run-all is in your package.json devDependencies .确保npm-run-all在你的 package.json devDependencies
  2. If npm-run-all is present in your package.json, run npm i如果您的 package.json 中存在npm-run-all ,请运行npm i
  3. If not present install it, run: npm i npm-run-all -D如果不存在安装它,运行: npm i npm-run-all -D

If error is still present, follow these steps:如果错误仍然存​​在,请按照下列步骤操作:

  1. Remove node_modules folder: run rm -rf node_modules删除 node_modules 文件夹:运行rm -rf node_modules
  2. Install all dependecies: run npm i安装所有依赖:运行npm i

Hope this helps!希望这可以帮助!

您可能只需要先运行以下命令(从包含 package.json 文件的目录中)

npm install

You have a couple of options here, besides installing npm-run-all as a global package as suggested by @Vaibhav in the comments:除了按照@Vaibhav 在评论中的建议将npm-run-all安装为全局包之外,您还有几个选择:

1) Create an NPM script 1) 创建NPM 脚本

The package.json file has a scripts section which can used to define shortcuts for anything you need to run while you're working on your app. package.json文件有一个scripts部分,可用于为您在处理应用程序时需要运行的任何内容定义快捷方式。 There are some pre-defined scripts, like run or test than can be executed with simply npm start / npm test or you can define anything you like and then run it with npm run my-script-name .有一些预定义的脚本,例如runtest ,可以通过简单的npm start / npm test执行,或者您可以定义任何您喜欢的内容,然后使用npm run my-script-name运行它。 You could try:你可以试试:

{
  "scripts": {
    "start": "npm-run-all -p build-css build-webpack"
  }
}

Any NPM module referenced here "just works" (ie the path to the executable is resolved under the hood by NPM)此处引用的任何 NPM 模块都“正常工作”(即,可执行文件的路径由 NPM 在后台解析)

2) NPX 2) NPX

In newer versions of NPM (ie >= 5.2 or so), the "NPX" executable is provided.在较新版本的 NPM(即 >= 5.2 左右)中,提供了“NPX”可执行文件。 This has a similar effect to running commands inside an NPM script.这与在 NPM 脚本中运行命令的效果类似。 You would run:你会运行:

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

Please do that like this.请这样做。

npm i npm-run-all -g

And then this issue will be fixed.然后这个问题将被修复。

npm install -g npm-run-all npm install -g npm-run-all

Works for me.为我工作。

Double check if npm-run-all is in your package.json devDependencies .仔细检查npm-run-all是否在您的package.json devDependencies

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

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.我不知道这是否对任何人有帮助,但我收到此错误是因为我正在执行 nodemon server.js 而不是 nodemon server/server.js。 I wasn't in the right folder!我没有在正确的文件夹中!

Did you reopen the terminal after you installed node?安装节点后是否重新打开终端?

If you have installed npm with the current terminal window open.如果您在当前终端窗口打开的情况下安装了 npm。 Your terminal window will not have loaded the latest path settings (with npm location) to find the npm application to run the command.您的终端窗口将不会加载最新的路径设置(带有 npm 位置)来查找 npm 应用程序来运行命令。 In this case try below steps .在这种情况下,请尝试以下步骤。

  1. Try closing the current terminal session.尝试关闭当前终端会话。
  2. Reopen a new session.重新打开一个新会话。
  3. Try the command again ( will pick up the new path settings with npm installed)再次尝试该命令(将选择安装了 npm 的新路径设置)

This worked for me.这对我有用。

npm audit fix --force

Also you can try downgrading your autoprefixer, seems version 10.0.0 doesn't work well with postcss你也可以尝试降级你的自动前缀,似乎 10.0.0 版本不适用于 postcss

npm i autoprefixer@9.8.6

暂无
暂无

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

相关问题 bin 不被识别为内部或外部命令。 npm 脚本 - bin is not recognized as an internal or external command. npm script create-react-app 上的“'npm' 未被识别为内部或外部命令” - "'npm' is not recognized as an internal or external command" on create-react-app Npm脚本始终会给出错误,因为“未被识别为内部或外部命令” - Npm scripts always gives an error as “is not recognized as an internal or external command” 运行项目时,“open”未被识别为内部或外部命令(npm start) - 'open' is not recognized as an internal or external command while running project (npm start) 无法将“ nodeunit”识别为内部或外部命令, - 'nodeunit' is not recognized as an internal or external command, “vue”未被识别为内部或外部命令 - 'vue' is not recognized as an internal or external command “服务”不被识别为运行反应应用程序的内部或外部命令 - 'serve' is not recognized as an internal or external command to run react app 'expo' 未被识别为内部或外部命令 - 'expo' is not recognized as an internal or external command Cat不被视为内部或外部命令 - Cat is not recognized as an internal or external command React-native:[NODEMON] 启动 `babel-node src`,“babel-node”未被识别为内部或外部命令,而我运行“npm run dev” - React-native: [NODEMON] starting `babel-node src`, "babel-node" is not recognized as an internal or external command, while I run 'npm run dev'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM