Command-Line-Interface

npm 安裝,但無法執行

  • January 6, 2017

我是 Node 的新手,但我一直在嘗試安裝一些 npm 模組,並且在似乎成功安裝之後,我無法執行新應用程序。我必須有一些基本的配置錯誤,比如我的 PATH 中缺少位置……

例如,執行:

npm install -g karma

我得到:

npm http GET https://registry.npmjs.org/karma
npm http 304 https://registry.npmjs.org/karma
npm http GET https://registry.npmjs.org/glob
... (many, many GETs......)

> ws@0.4.25 install /usr/local/share/npm/lib/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

 CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
 SOLINK_MODULE(target) Release/bufferutil.node
 SOLINK_MODULE(target) Release/bufferutil.node: Finished
 CXX(target) Release/obj.target/validation/src/validation.o
 SOLINK_MODULE(target) Release/validation.node
 SOLINK_MODULE(target) Release/validation.node: Finished
/usr/local/share/npm/bin/karma -> /usr/local/share/npm/lib/node_modules/karma/bin/karma

> karma@0.8.3 install /usr/local/share/npm/lib/node_modules/karma
> node install-log4js.js

npm http GET https://registry.npmjs.org/log4js/0.6.2
npm http 304 https://registry.npmjs.org/log4js/0.6.2
npm http GET https://registry.npmjs.org/async/0.1.15
npm http GET https://registry.npmjs.org/dequeue/1.0.3
npm http 304 https://registry.npmjs.org/dequeue/1.0.3
npm http 304 https://registry.npmjs.org/async/0.1.15
log4js@0.6.2 /usr/local/share/npm/lib/node_modules/log4js
├── dequeue@1.0.3
└── async@0.1.15
karma@0.8.3 /usr/local/share/npm/lib/node_modules/karma
├── pause@0.0.1
├── dateformat@1.0.2-1.2.3
├── xmlbuilder@0.4.2
├── colors@0.6.0-1
├── chokidar@0.6.2
├── growly@1.1.1
├── mime@1.2.9
├── q@0.9.2
├── coffee-script@1.6.2
├── lodash@1.1.1
├── rimraf@2.1.4 (graceful-fs@1.2.0)
├── optimist@0.3.5 (wordwrap@0.0.2)
├── minimatch@0.2.11 (sigmund@1.0.0, lru-cache@2.3.0)
├── glob@3.1.21 (inherits@1.0.0, graceful-fs@1.2.0)
├── LiveScript@1.0.1 (prelude-ls@0.6.0)
├── log4js@0.6.2 (dequeue@1.0.3, async@0.1.15)
├── http-proxy@0.10.0 (pkginfo@0.2.3, utile@0.1.7)
├── istanbul@0.1.22 (abbrev@1.0.4, which@1.0.5, fileset@0.1.5, nopt@2.0.0, wordwrap@0.0.2, async@0.1.22, mkdirp@0.3.5, esprima@0.9.9, handlebars@1.0.10, escodegen@0.0.20)
└── socket.io@0.9.14 (base64id@0.1.0, policyfile@0.0.4, redis@0.7.3, socket.io-client@0.9.11)

但是當我嘗試執行時:

➤ karma start
fish: Unknown command 'karma'

當然,如果我通過直接解決整個 karma 路徑來執行它,它可以正常工作:

/usr/local/share/npm/lib/node_modules/karma/bin/karma start

Starting Testacular Server (http://vojtajina.github.com/testacular)
-------------------------------------------------------------------
INFO [karma]: Karma server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 26.0 (Mac)]: Connected on socket id sNhp2l8FW6zQ0iQsiRgR
Chrome 26.0 (Mac): Executed 1 of 1 SUCCESS (0.108 secs / 0.004 secs)

當我 npm install 時,不是在某處創建了符號連結嗎?

➤ which npm
/usr/local/bin/npm

➤ npm --version
1.2.14

我通過將 /usr/local/share/npm/bin 添加到我的路徑來做到這一點。(通過編輯我的 .bashrc 文件)

export PATH=/usr/local/bin:/usr/local/lib:/opt/local/bin:/opt/local/sbin:/usr/local/share/npm/bin:$PATH

請參閱此 Karma 設置頁面

跑:

npm install karma-cli -g

你現在應該可以跑karma start了。

引用自:https://serverfault.com/questions/495908