我也在使用 Ubuntu 12.04,并且遇到了同样的问题(尽管我不认为这特别是 Ubuntu 的错)。
grimbo@grimbo-ubuntu-12:~/git/SyntaxHighlighter$ npm
module.js:340
throw err;
^
Error: Cannot find module 'graceful-fs'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/usr/share/npm/lib/utils/ini.js:32:10)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
所以我试图找出 npm 从哪里运行:
grimbo@grimbo-ubuntu-12:~/git/SyntaxHighlighter$ sudo find / -name npm
/etc/bash_completion.d/npm
/usr/bin/npm
/usr/local/bin/npm
/usr/local/n/versions/0.8.7/bin/npm
/usr/local/n/versions/0.8.7/lib/node_modules/npm
/usr/local/n/versions/0.8.7/lib/node_modules/npm/bin/npm
/usr/share/lintian/overrides/npm
/usr/share/doc/npm
/usr/share/npm
/usr/share/doc-base/npm
/usr/lib/nodejs/npm
/var/lib/doc-base/documents/npm
作为参考,这些是几个链接:
/usr/bin/npm -> ../share/npm/bin/npm-cli.js*
/usr/local/n/versions/0.8.7/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js*
确认正在使用的是“/usr/bin/npm”:
grimbo@grimbo-ubuntu-12:~/git/SyntaxHighlighter$ which npm
/usr/bin/npm
因此,我尝试专门调用最新的,这似乎可以解决问题:
grimbo@grimbo-ubuntu-12:~/git/SyntaxHighlighter$ /usr/local/n/versions/0.8.7/bin/npm install
npm WARN package.json SyntaxHighlighter@3.0.83 No README.md file found!
npm http GET https://registry.npmjs.org/uglify-js
npm http GET https://registry.npmjs.org/less
npm http GET https://registry.npmjs.org/jake
npm http GET https://registry.npmjs.org/minimatch
npm http 200 https://registry.npmjs.org/uglify-js
npm http GET https://registry.npmjs.org/uglify-js/-/uglify-js-1.3.3.tgz
npm http 200 https://registry.npmjs.org/less
npm http GET https://registry.npmjs.org/less/-/less-1.3.0.tgz
npm http 200 https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/minimatch/-/minimatch-0.2.6.tgz
npm http 200 https://registry.npmjs.org/less/-/less-1.3.0.tgz
npm http 200 https://registry.npmjs.org/uglify-js/-/uglify-js-1.3.3.tgz
npm http 200 https://registry.npmjs.org/minimatch/-/minimatch-0.2.6.tgz
npm http 200 https://registry.npmjs.org/jake
npm http GET https://registry.npmjs.org/jake/-/jake-0.3.14.tgz
npm http 200 https://registry.npmjs.org/jake/-/jake-0.3.14.tgz
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/utilities
npm http GET https://registry.npmjs.org/minimatch
npm http 304 https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/minimatch/-/minimatch-0.0.5.tgz
npm http 200 https://registry.npmjs.org/utilities
npm http GET https://registry.npmjs.org/utilities/-/utilities-0.0.11.tgz
npm http 200 https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/lru-cache/-/lru-cache-2.0.1.tgz
npm http 200 https://registry.npmjs.org/minimatch/-/minimatch-0.0.5.tgz
npm http 200 https://registry.npmjs.org/utilities/-/utilities-0.0.11.tgz
npm http 200 https://registry.npmjs.org/lru-cache/-/lru-cache-2.0.1.tgz
npm http GET https://registry.npmjs.org/lru-cache
npm http 304 https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/lru-cache/-/lru-cache-1.0.6.tgz
npm http 200 https://registry.npmjs.org/lru-cache/-/lru-cache-1.0.6.tgz
npm WARN prefer global jake@0.3.14 should be installed with -g
uglify-js@1.3.3 node_modules/uglify-js
less@1.3.0 node_modules/less
minimatch@0.2.6 node_modules/minimatch
+-- lru-cache@2.0.1
jake@0.3.14 node_modules/jake
+-- utilities@0.0.11
+-- minimatch@0.0.5 (lru-cache@1.0.6)
最终,看起来可能是因为我过去安装了其他版本的 node 和 npm,所以它变得很困惑。