本文介绍了安装 Gulp 后:“找不到命令 'gulp'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过 npm 安装 gulp.js 后,我收到 no command 'gulp' found 从安装到的同一目录中运行 gulp 命令时出错.

After installing gulp.js via npm, I receive a no command 'gulp' found error when running the gulp command from the same directory it was installed into.

node_modules/.bin/ 目录下查看时,我可以在那里看到 gulp 可执行文件.

When looking under the node_modules/.bin/ directory, I can see the gulp executable there.

我的 npm 安装有问题吗?

Is there something wrong with my npm installation?

推荐答案

这很正常.如果您希望 gulp-cli 在命令行上可用,则需要全局安装.

That's perfectly normal.If you want gulp-cli available on the command line, you need to install it globally.

npm install --global gulp-cli

请参阅安装说明.

此外,node_modules/.bin/ 不在您的 $PATH 中.但是它是在运行 npm 脚本时由 npm 自动添加的(请参阅这篇博文以供参考).

Also, node_modules/.bin/ isn't in your $PATH. But it is automatically added by npm when running npm scripts (see this blog post for reference).

因此您可以将 scripts 添加到您的 package.json 文件中:

So you could add scripts to your package.json file:

{
    "name": "your-app",
    "version": "0.0.1",
    "scripts": {
        "gulp": "gulp",
        "minify": "gulp minify"
    }
}

然后您可以运行 npm run gulpnpm run minify 来启动 gulp 任务.

You could then run npm run gulp or npm run minify to launch gulp tasks.

这篇关于安装 Gulp 后:“找不到命令 'gulp'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 02:00