npm 安装,但无法运行

npm 安装,但无法运行

我是 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......)

> [email protected] 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

> [email protected] 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
[email protected] /usr/local/share/npm/lib/node_modules/log4js
├── [email protected]
└── [email protected]
[email protected] /usr/local/share/npm/lib/node_modules/karma
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected])

但是当我尝试运行时:

➤ 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 安装某些东西时,是不是在某处创建了符号链接?

➤ which npm
/usr/local/bin/npm

➤ npm --version
1.2.14

答案1

我通过将 /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

答案2

此 Karma 设置页面

跑步:

npm install karma-cli -g

你现在应该可以跑了karma start

相关内容