【问题标题】:why doesn't gulp run when installed globally?为什么全局安装时 gulp 不运行?
【发布时间】:2016-12-19 19:25:48
【问题描述】:

我使用 npm install -g gulp 安装 gulp

[npm WARN deprecation warnings redacted]
/usr/local/bin/gulp -> /usr/local/lib/node_modules/gulp/bin/gulp.js
/usr/local/lib
└── gulp@3.9.1 

当我尝试运行 gulp 命令时,我得到:

gulp
[19:42:23] Local gulp not found in ~/javascript
[19:42:23] Try running: npm install gulp

但是当我在全球范围内安装另一个 npm 包时,它可以工作。例如,当我像这样安装create-react-app 时:

npm install -g create-react-app
/usr/local/bin/create-react-app -> /usr/local/lib/node_modules/create-react-app/index.js
/usr/local/lib
└─┬ create-react-app@0.2.0 
  ├─┬ chalk@1.1.3 
  │ ├── ansi-styles@2.2.1 
  │ ├── escape-string-regexp@1.0.5 
  │ ├─┬ has-ansi@2.0.0 
  │ │ └── ansi-regex@2.0.0 
  │ ├── strip-ansi@3.0.1 
  │ └── supports-color@2.0.0 
  ├─┬ cross-spawn@4.0.0 
  │ ├─┬ lru-cache@4.0.1 
  │ │ ├── pseudomap@1.0.2 
  │ │ └── yallist@2.0.0 
  │ └─┬ which@1.2.10 
  │   └── isexe@1.1.2 
  ├── minimist@1.2.0 
  └── semver@5.3.0 

当我在安装后运行命令时,它可以工作:

create-react-app
Usage: create-react-app <project-directory> [--verbose]

gulp 有什么原因会搞砸吗?

【问题讨论】:

  • npm bin 位于何处?输入npm bin -g,当你得到输出时,尝试直接从该路径运行命令,例如在我的笔记本电脑上是它所在的位置:/home/kyle/.linuxbrew/bin。所以我可以运行/home/kyle/.linuxbrew/bin/gulp,它就会运行。如果您没有看到此命令,则可能意味着您的 $PATH 变量中没有此路径设置,因此您需要编辑您的 .bash_profile(或适当的文件,如果您将其放在其他地方或使用Zsh 或其他 shell)。
  • npm bin 路径在我的 $PATH 中

标签: npm gulp


【解决方案1】:

你必须安装 Gulp CLI 才能让命令行工作npm install -g gulp-cli

【讨论】:

  • 它可能不会那样工作。甚至他们的教程都说要全局安装 CLI,然后将 Gulp 作为包依赖项。我一直都安装了,从来没有尝试过只使用全局安装来完成
猜你喜欢
  • 1970-01-01
  • 2018-03-10
  • 2017-06-27
  • 1970-01-01
  • 2017-01-05
  • 2021-05-28
  • 2014-04-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多