node.js 未找到 gulp 命令 - 安装 gulp 后出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24027551/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:26:46  来源:igfitidea点击:

gulp command not found - error after installing gulp

windowsnode.jsgulp

提问by pedalpete

I've installed gulp both globally and locally using

我已经使用全局和本地安装了 gulp

npm install gulp
npm install gulp -g
npm install gulp-util
npm install gulp-util -g

When try to run gulp i get

当尝试运行 gulp 我得到

'gulp' is not recognized as an internal or external command, operable program or batch file.

'gulp' is not recognized as an internal or external command, operable program or batch file.

Running npm list gulp (or -g), I [email protected]with the location of either my global or local gulp installation.

运行 npm list gulp(或 -g),我[email protected]可以找到全局或本地 gulp 安装的位置。

I've tried running node gulpfile.jspointed to my gulpfile, and it runs without error, and of course, it starts with require('gulp').

我试过运行node gulpfile.js指向我的 gulpfile,它运行没有错误,当然,它以require('gulp').

Any suggestions on getting gulp working on Windows(8.1)?

关于让 gulp 在 Windows(8.1) 上工作的任何建议?

回答by csnate

You forgot to install the gulp-cli package:

你忘记安装 gulp-cli 包:

npm install -g gulp-cli

Then you can run the command "gulp" from the command line.

然后你可以从命令行运行命令“gulp”。

回答by SteveLacy

The issue and answer can be found in this question: https://stackoverflow.com/a/9588052/1041104

问题和答案可以在这个问题中找到:https: //stackoverflow.com/a/9588052/1041104

The npm modules such as gulp are not installed to the path. Thus are not found when you run them in the CMD.

gulp 等 npm 模块没有安装到路径中。因此在 CMD 中运行它们时找不到。

If gulp has been installed globally, you can use the process below:

如果已经全局安装了 gulp,则可以使用以下流程:

  1. Create an environmental variable called NODE_PATH
  2. Set it to: %AppData%\npm\node_modulesor %AppData%\npmon windows 8-10
  3. Close CMD, and Re-Open to get the new ENV variables
  1. 创建一个名为的环境变量 NODE_PATH
  2. 将其设置为:%AppData%\npm\node_modules%AppData%\npm在 Windows 8-10 上
  3. 关闭 CMD,然后重新打开以获取新的 ENV 变量

Add Node path to environmental variables

将节点路径添加到环境变量

Running npm lsand npm ls -gshows that they are installed, but the CMD can not find them due to the missing link.

运行npm lsnpm ls -g显示它们已安装,但由于the missing link.

回答by Habib Ad?belli

  1. Be sure that you have gulp and gulp.cmd(use windows search)
  2. Copy the path of gulp.cmd(C:\Users\XXXX\AppData\Roaming\npm)
  3. Add this path to the Path envirement variable oredit PATHenvironment variable and add %APPDATA%\npm
  4. Reopen cmd.
  1. 确保你有 gulp 和gulp.cmd(使用 Windows 搜索)
  2. 复制( )的路径gulp.cmdC:\Users\XXXX\AppData\Roaming\npm
  3. 将此路径添加到 Path 环境变量编辑PATH环境变量并添加%APPDATA%\npm
  4. 重新打开cmd。

Add %APPDATA%\npmto front of Path, not end of the Path.

添加%APPDATA%\npm到路径的前面,而不是路径的末尾。

回答by Gaurav Goel

  1. Install gulp globally.

    npm install -g gulp

  2. Install gulp locally in the project.

    npm install gulp

  3. Add below line in your package.json

    "scripts": { "gulp": "gulp" }

  4. Run gulp.

    npm run gulp

  1. 全局安装 gulp。

    npm install -g gulp

  2. 在项目中本地安装 gulp。

    npm install gulp

  3. 在 package.json 中添加以下行

    "scripts": { "gulp": "gulp" }

  4. 运行一口。

    npm run gulp

This worked for me.

这对我有用。

回答by Sudarsan GP

I am using Windows 8.1. I had the same problem.

我正在使用 Windows 8.1。我有同样的问题。

I installed gulp using Node.js command prompt

我使用 Node.js 命令提示符安装了 gulp

npm install -g gulp

Then go to the required directory in Node.js command prompt and try

然后转到 Node.js 命令提示符中所需的目录并尝试

gulp -v

If you get gulp local version not found exit the current Node.js command prompt and try the above command in a new Node.js command prompt

如果找不到 gulp 本地版本,请退出当前的 Node.js 命令提示符并在新的 Node.js 命令提示符中尝试上述命令

I tried the NODE_PATH mentioned by @SteveLacy but the command prompt was still not able to detect gulp command

我尝试了@SteveLacy 提到的 NODE_PATH 但命令提示符仍然无法检测到 gulp 命令

回答by Namek

Had the same problem, not really best solution but install it globally:

有同样的问题,不是最好的解决方案,而是全局安装:

npm install -g gulp

Of course it's best to still have it in package.json, so you can do the following to install it locally and add an entry into package.json:

当然,最好还是有它在package.json,所以你可以做以下的在本地安装它,并添加一个条目package.json

npm install --save-dev gulp

Everything else (gulp plugins) install also locally.

其他所有东西(gulp 插件)也在本地安装。

回答by miojamo

The simple solution just do npm link gulp

简单的解决方案就是这样做 npm link gulp

回答by Spaceman

I was having the same problem when trying to get gulp working on a co-workers VM. It seems the problem stems from the users folder.

我在尝试让 gulp 在同事 VM 上工作时遇到了同样的问题。似乎问题源于用户文件夹。

Adding NODE_PATH in my environment variables didn't fix the problem.

在我的环境变量中添加 NODE_PATH 并没有解决问题。

If you edit your 'Path' variable in your system variables and add '%APPDATA%\npm' at the end of that, it should fix the problem... Unless you or somebody else npm installed gulp as another user than the one you're currently logged in as.

如果您在系统变量中编辑“路径”变量并在其末尾添加“%APPDATA%\npm”,它应该可以解决问题...除非您或其他人将 gulp 安装为其他用户而不是您的用户'当前登录为。

If you want it to be available for all users, put 'C:\Users\yourUser\AppData\Roaming\npm'(or where ever you have gulp) explicitly instead of using '%APPDATA%\npm'. You can also move the files to a more user-indifferent path.

如果您希望所有用户都可以使用它,请明确放置“C:\Users\yourUser\AppData\Roaming\npm”(或任何有吞咽的地方),而不是使用“%APPDATA%\npm”。您还可以将文件移动到更不受用户影响的路径。

Don't forget to start a new cmd prompt, because the one you have open won't get the new 'Path' variable automatically.

不要忘记启动一个新的 cmd 提示符,因为您打开的那个不会自动获得新的 'Path' 变量。

Now 'gulp'.

现在'吞咽'。

回答by yeralin

One right way:

一种正确的方法:

  1. Cmd + R : type "%appdata%"
  2. Go to npm folder
  3. Copy whole path like "C:\Users\Blah...\npm\"
  4. Go to My Computer + Right Click "Properties"
  5. Advanced System Settings (On the left)
  6. Click on Environment Variables
  7. Click on Edit Path
  8. Add that "C:\Users\Blah...\npm\" to the end and type ";" after that
  9. Click ok and reopen cmd
  1. Cmd + R : 输入“%appdata%”
  2. 转到 npm 文件夹
  3. 复制整个路径,如“C:\Users\Blah...\npm\”
  4. 转到我的电脑+右键单击“属性”
  5. 高级系统设置(左侧)
  6. 点击环境变量
  7. 点击编辑路径
  8. 将 "C:\Users\Blah...\npm\" 添加到末尾并键入 ";" 在那之后
  9. 单击确定并重新打开cmd

回答by Badr Bellaj

You should first install gulpas global using:

您应该首先gulp使用以下方法安装为全局:

npm install gulp -g

Otherwise the path solution will not resolve the problem.

否则路径解决方案将无法解决问题。

Then add the npm modules path to the PATH using:

然后使用以下命令将 npm 模块路径添加到 PATH:

PATH = %PATH%;%APPDATA%\npm