node.js 'gulp' 未被识别为内部或外部命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39195128/
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
'gulp' is not recognized as an internal or external command
提问by Junior
I am trying to use Gulpand Node.Jsto stream my process for minifying and concatenating CSS/JS files for production.
我正在尝试使用Gulp和Node.Js来流式传输我的过程,以缩小和连接 CSS/JS 文件以进行生产。
Here is what I have done.
这是我所做的。
- I installed Node.Json my Windows 7 machine.
- Installed Gulp globally using this command
npm install -g gulp - Then I added a new User variable called
NODE_PATHset it to%AppData%\npm\node_modules
- 我在 Windows 7 机器上安装了Node.Js。
- 使用此命令全局安装 Gulp
npm install -g gulp - 然后我添加了一个名为
NODE_PATH将其设置为的新用户变量%AppData%\npm\node_modules
After closing and re-opening my command line, I tried to run a gulp task from the command line (i.e. gulp css). But that give me the following error
关闭并重新打开命令行后,我尝试从命令行(即gulp css)运行 gulp 任务。但这给了我以下错误
'gulp' is not recognized as an internal or external command
How can I get this to work?
我怎样才能让它发挥作用?
When I opened the following path using the search bar in windows,
%AppData%\npm\node_modulesI see the following two folders
当我在windows中使用搜索栏打开以下路径时,
%AppData%\npm\node_modules看到如下两个文件夹
gulp
gulp-cli
I've tried to add %AppData%\npm\node_modulesto the Pathvariable on my system variable, but it did not take it because that variable reached it's max allowed character limit.
我试图添加%AppData%\npm\node_modules到Path我的系统变量上的变量,但它没有接受它,因为该变量达到了它的最大允许字符限制。
I removed couple of paths from my Pathvariable and added ;C:\Users\[MyWindowsUserName]\AppData\Roaming\npm\node_modules
我从Path变量中删除了几个路径并添加了;C:\Users\[MyWindowsUserName]\AppData\Roaming\npm\node_modules
but still not working.
但仍然无法正常工作。
I even tried to set the path at run time using this command
我什至尝试在运行时使用此命令设置路径
PATH=%PATH%;C:\Users\[MyWindowsUserName]\AppData\Roaming\npm\node_modulesthen run gulpand still the same issues.
PATH=%PATH%;C:\Users\[MyWindowsUserName]\AppData\Roaming\npm\node_modules然后运行gulp,还是一样的问题。
What am I missing here? What else do I need in order to get this to work?
我在这里缺少什么?我还需要什么才能让它发挥作用?
采纳答案by Junior
I solved the problem by uninstalling NodeJs and gulp then re-installing both again.
我通过卸载 NodeJs 和 gulp 然后重新安装两者来解决这个问题。
To install gulp globally I executed the following command
要全局安装 gulp,我执行了以下命令
npm install -g gulp
回答by tomcat
I had similar issue when I installed locally initially(w/o -g). I reinstalled with -g (global) and then it worked.
我最初在本地安装时遇到了类似的问题(w/o -g)。我用 -g (全局)重新安装,然后它工作了。
npm install -g gulp
you should run gulp from folder where gulpfile.jsis available.
您应该从gulpfile.js可用的文件夹中运行 gulp 。
回答by Vinod R
Go to My Computer>Properties>Advance System Settings>Environment Variables>
去 My Computer>Properties>Advance System Settings>Environment Variables>
Under the variables of Administrator edit the PATH variable & change its value to "C:\Users\Username\AppData\Roaming\npm". Note: The username in the path will be the current Admin user's name that you have logged in with.
在 Administrator 的变量下编辑 PATH 变量并将其值更改为"C:\Users\Username\AppData\Roaming\npm". 注意:路径中的用户名将是您登录时使用的当前管理员用户名。
回答by Matiiii
I had the same problem on windows 7. You must edit your path system variable manually.
我在 Windows 7 上遇到了同样的问题。您必须手动编辑路径系统变量。
Go to START -> edit the system environment variables -> Environment variables -> in system part find variables "Path" -> edit -> add new path after ";" to your file gulp.cmd directory some like ';C:\Users\YOURUSERNAME\AppData\Roaming\npm' -> click ok and close these windows -> restart your CLI -> enjoy
转到开始->编辑系统环境变量->环境变量->在系统部分找到变量“路径”->编辑->在“;”后添加新路径 到你的文件 gulp.cmd 目录,比如 ';C:\Users\YOURUSERNAME\AppData\Roaming\npm' -> 单击确定并关闭这些窗口 -> 重新启动你的 CLI -> 享受
回答by Anas Choudhary
If you have mysql install in your windows 10 try uninstall every myqsl app from your computer. Its work for me. exactly when i installed the mysql in my computer gulp command and some other commands stop working and then i have tried everything but not nothing worked for me.
如果您在 Windows 10 中安装了 mysql,请尝试从您的计算机上卸载每个 myqsl 应用程序。它对我来说有效。正是当我在我的计算机 gulp 命令中安装 mysql 时,其他一些命令停止工作,然后我尝试了一切,但对我来说没有任何效果。
回答by ibrahimozgon
I was having the same exception with node v12.13.1,
我在 node v12.13.1 上遇到了同样的异常,
Downgradednode to v10.15.3 and it works fine now.
将节点降级到 v10.15.3,现在可以正常工作了。
回答by Markus Bauer
In my case, this problem occured because I did npm installwith another system user in my project folder before. Gulp was already installed globally. After deleting folder /node_modules/in my project, and running npm installwith the current user, it worked.
就我而言,发生此问题是因为我之前npm install在我的项目文件夹中使用了另一个系统用户。Gulp 已经在全球范围内安装。在我的项目中删除文件夹/node_modules/并npm install使用当前用户运行后,它起作用了。
回答by Amit Sharma
You need to make sure, when you run command (install npm -g gulp), it will create install gulp on C:\ directory.
您需要确保,当您运行命令(安装 npm -g gulp)时,它会在 C:\ 目录中创建安装 gulp。
that directory should match with whatver npm path variable set in your java path.
该目录应该与您的 java 路径中设置的任何 npm 路径变量相匹配。
just run path from command prompt, and verify this. if not, change your java class path variable wherever you gulp is instaled.
只需从命令提示符运行路径,并验证这一点。如果没有,请在安装 gulp 的任何地方更改 java 类路径变量。
It should work.
它应该工作。
回答by Henry Ollarves
Sorry that was a typo. You can either add node_modules to the end of your user's global path variable, or maybe check the permissions associated with that folder (node _modules). The error doesn't seem like the last case, but I've encountered problems similar to yours. I find the first solution enough for most cases. Just go to environment variables and add the path to node_modules to the last part of your user's path variable. Note I'm saying user and not system.
对不起,这是一个错字。您可以将 node_modules 添加到用户全局路径变量的末尾,或者检查与该文件夹(节点 _modules)关联的权限。该错误似乎不是最后一种情况,但我遇到了与您类似的问题。对于大多数情况,我发现第一个解决方案就足够了。只需转到环境变量并将 node_modules 的路径添加到用户路径变量的最后一部分。注意我说的是用户而不是系统。
Just add a semicolon to the end of the variable declaration and add the static path to your node_module folder. ( Ex c:\path\to\node_module)
只需在变量声明的末尾添加一个分号,并将静态路径添加到您的 node_module 文件夹中。( 例如 c:\path\to\node_module)
Alternatively you could:
或者你可以:
In your CMD
在你的 CMD
PATH=%PATH%;C:\path\to\node_module
EDIT
编辑
The last solution will work as long as you don't close your CMD. So, use the first solution for a permanent change.
只要您不关闭 CMD,最后一个解决方案就会起作用。因此,请使用第一个解决方案进行永久性更改。
回答by balaji s
The best solution, you can manage the multiple node versions using nvm installer. then, install the required node's version using below command
最好的解决方案,您可以使用 nvm 安装程序管理多个节点版本。然后,使用以下命令安装所需节点的版本
nvm install version
Use below command as a working node with mentioned version alone
使用以下命令作为单独提到版本的工作节点
nvm use version
now, you can use any version node without uninstalling previous installed node.
现在,您可以使用任何版本的节点,而无需卸载以前安装的节点。


