node.js NPM,无论我做什么,都找不到“优雅的 fs”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11379919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NPM, cannot find 'graceful-fs', no matter what I do
提问by Collin McGuire
This is what I get when I try to install express for node.js
这是我尝试为 node.js 安装 express 时得到的结果
npm install express
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)
I even tried others and still got the same error. I did some digging and i did find 'gracefui-fs' on my server.
我什至尝试了其他人,但仍然遇到相同的错误。我做了一些挖掘,我确实在我的服务器上找到了“gracefui-fs”。
I am running ubuntu 12.04 LTS on an amazon ec2 server. Node installed with no errors, and npm still didn't work. I also un installed and re installed npm using
我在亚马逊 ec2 服务器上运行 ubuntu 12.04 LTS。Node 安装没有错误,npm 仍然没有工作。我也未安装并使用重新安装 npm
apt-get
as well as from source. During installation I received no errors either.
以及从源头。在安装过程中,我也没有收到任何错误。
回答by Giuliani
Had the same problem. Don't download npmfrom aptitudeor apt-get.
有同样的问题。不要npm从aptitude或下载apt-get。
Instead try:
而是尝试:
git clone --depth=1 git://github.com/npm/cli.git
cd cli/scripts
chmod +x install.sh
sudo ./install.sh
saw it here: NPM can't install appjs. Error: Cannot find module 'graceful-fs'
回答by Max
I had the same problem.
我有同样的问题。
sudo npm install
solved it for me.
为我解决了。
回答by Paul Grime
I was also using Ubuntu 12.04, and was having this same issue (though I don't think it's specifically Ubuntu's fault).
我也在使用 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)
So i tried to work out where npm was running from:
所以我试图找出 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
For reference, these were a couple of the links:
作为参考,这些是几个链接:
/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*
Confirmation that it was "/usr/bin/npm" that was being used:
确认正在使用的是“/usr/bin/npm”:
grimbo@grimbo-ubuntu-12:~/git/SyntaxHighlighter$ which npm
/usr/bin/npm
So I tried to call the latest one specifically, which seemed to do the trick:
所以我尝试专门调用最新的,这似乎可以解决问题:
grimbo@grimbo-ubuntu-12:~/git/SyntaxHighlighter$ /usr/local/n/versions/0.8.7/bin/npm install
npm WARN package.json [email protected] 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 [email protected] should be installed with -g
[email protected] node_modules/uglify-js
[email protected] node_modules/less
[email protected] node_modules/minimatch
+-- [email protected]
[email protected] node_modules/jake
+-- [email protected]
+-- [email protected] ([email protected])
Ultimately, it looks like maybe because I've had other versions of node and npm installed in the past, it just got confused.
最终,看起来可能是因为我过去安装了其他版本的 node 和 npm,它只是感到困惑。
回答by Kevin Meyer
So after installing node_js and npm, I was having the same problem
所以在安装 node_js 和 npm 后,我遇到了同样的问题
my-app$ locate graceful-fs
/usr/lib/nodejs/graceful-fs
... some other junk we don't care about ...
my-app$ export NODE_PATH=/usr/lib/nodejs
my-app$ npm update
... it works ...
回答by Prut Udomwattawee
Just for my two cents. I install with
只为我的两分钱。我安装
sudo npm install -g graceful-fs
This install graceful-fs globally and it solved my issue.
这在全局安装了优雅的 fs,它解决了我的问题。
回答by Artjom Kurapov
Had similar problem on Ubuntu while installing phonegap, fixed it with
在 Ubuntu 上安装 phonegap 时遇到了类似的问题,用
sudo npm install graceful-fs
回答by VolodymyrB
I had Mint Node.js 8.x version but have upgraded via ncommand to 11.x. The problem was that n/npmonly replace binary or link in /usr/local/bindirectory, but not in /usr/bindirectory. So you should replace /usr/bin/node-gypwith /usr/local/bin/node-gypcontent:
我有 Mint Node.js 8.x 版本,但已通过n命令升级到 11.x。问题是n/npm只替换/usr/local/bin目录中的二进制文件或链接,而不是/usr/bin目录中的。所以你应该/usr/bin/node-gyp用/usr/local/bin/node-gyp内容替换:
sudo cp -f -s /usr/local/bin/node-gyp /usr/bin/node-gyp
sudo cp -f -s /usr/local/bin/node-gyp /usr/bin/node-gyp
回答by Jayanta
I use Windows; similar should work in Mac and Linux
我使用 Windows;类似的应该适用于 Mac 和 Linux
npm in cordova wrong and cordova uses private npm
科尔多瓦中的 npm 错误,科尔多瓦使用私有 npm
go to C:\Users\sssca_000\AppData\Roaming\npm\node_modules\cordova\node_modules Rename npm to npm_XXX
转到 C:\Users\sssca_000\AppData\Roaming\npm\node_modules\cordova\node_modules 将 npm 重命名为 npm_XXX
Go to C:\Users\sssca_000\AppData\Roaming\npm\node_modules This is where real npm resides Copy npm directory from here to C:\Users\sssca_000\AppData\Roaming\npm\node_modules\cordova\node_modules
转到 C:\Users\sssca_000\AppData\Roaming\npm\node_modules 这是真正的 npm 所在的位置 将 npm 目录从这里复制到 C:\Users\sssca_000\AppData\Roaming\npm\node_modules\cordova\node_modules
It worked fine for me!
它对我来说很好用!
回答by joshhua
By default Node looks for modules within your project in ../CollinsProject/node_modules.
默认情况下,Node 在你的项目中查找模块 ../CollinsProject/node_modules。
Try moving graceful-fs to this folder and it should work.
尝试将 graceful-fs 移动到此文件夹,它应该可以工作。
If you want to install the module to be used globally (across other projects), then move the graceful-fs folder to /usr/local/lib/node_modules.
如果要安装要全局使用的模块(跨其他项目),请将 graceful-fs 文件夹移动到/usr/local/lib/node_modules.
回答by Nux
The same also happens on Windows if you install in a custom directory. You have to uninstall and install again under default path.
如果安装在自定义目录中,Windows 上也会发生同样的情况。您必须在默认路径下重新卸载并安装。

