gpt4 book ai didi

node.js - 本地安装的 gulp 不在命令行中运行?

转载 作者:IT老高 更新时间:2023-10-28 22:10:24 25 4
gpt4 key购买 nike

我是 nodejs 和 gulp 的新手。我在一个 nodejs 项目上工作,我必须在所有文件上运行 jslint。为此,我正在使用 gulp。

我的问题是,为了在 cli 上运行 gulp,我不想全局安装 gulp,也不想更新我的路径变量,所以我已经使用包在本地项目中安装了 gulp 和其他 Node 模块.json 文件

cd myproject

npm install

因为我不想全局安装 gulp 并且想运行本地 gulp,所以我在我的 package.json 文件中添加了脚本,如 this 中给出的那样问题

{
"name": "",
"version": "1.0.0",
"main": "index.js",
"private": true,
"dependencies": {
"async": "1.5.0"
},
"devDependencies": {
"gulp": "^3.9.0",
"gulp-jslint": "^0.2.2"
},
"scripts": {
"gulp": "./node_modules/.bin/gulp" // is this correct?
}
}

在我的 myproject 文件夹中添加了一个 gulpfile.js

var gulp = require('gulp'); 

// include plug-ins
var jslint = require('gulp-jslint');

// JS hint task
gulp.task('lint', function() {
gulp.src('./common/srp/*.js')
.pipe(jslint())
.pipe(jslint.reporter('default'));
});

gulp.task("default", ["lint"]);

但是现在在 myproject 文件夹中的命令行上,当我运行 gulp 和 gulp lint 时出现错误

user1-VirtualBox:~/myproject$ gulp lint

/usr/local/node-v0.10.26-linux-x64/bin/gulp No such file or directory

它在全局 Node 模块中寻找 gulp。

有没有办法让 gulp 在 cli 上运行而无需全局安装和更新 PATH 变量。

任何帮助将不胜感激谢谢

最佳答案

您可以在 node_modules/.bin 中找到 npm 安装的任何可执行文件。因此,您可以使用以下命令在本地运行 gulp:

./node_modules/.bin/gulp

您可以在 no command 'gulp' found - after installation 找到更多信息

关于node.js - 本地安装的 gulp 不在命令行中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33677545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com