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