node.js 尝试运行 grunt 时找不到模块“findup-sync”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15444020/
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
Cannot find module 'findup-sync' when trying to run grunt
提问by Tim Martin
I am having trouble running grunt-cliafter installing it. I run
grunt-cli安装后我无法运行。我跑
npm install -g grunt-cli
then running grunt errors with
然后运行 grunt 错误
node.js:63
throw e;
^
Error: Cannot find module 'findup-sync'
at loadModule (node.js:275:15)
at require (node.js:411:14)
at Object.<anonymous> (/home/tmartin/bin/grunt:9:14)
at Module._compile (node.js:462:23)
at Module._loadScriptSync (node.js:469:10)
at Module.loadSync (node.js:338:12)
at Object.runMain (node.js:522:24)
at Array.<anonymous> (node.js:756:12)
at EventEmitter._tickCallback (node.js:55:22)
at node.js:773:9
This is what I have installed:
这是我安装的:
tmartin@timcomp:~$ npm list -g
/home/tmartin/lib
└─┬ [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ └── [email protected]
└─┬ [email protected]
└── [email protected]
回答by Xavier Haniquaut
I got mine running again reinstalling grunt-cli globally and in my repo.
我让我的再次运行,在全局和我的回购中重新安装了 grunt-cli。
npm install -g grunt-cli
npm install -g grunt-cli
cd myrepo
cd myrepo
npm install grunt-cli
npm install grunt-cli
I think Yosemite installation broke some things in my files ...
我认为优胜美地安装破坏了我的文件中的一些东西......
回答by Matthew Fotzler
I had to install and link findup-sync and a few other npm packages to get these dependency issues to go away. I though npm was supposed to handle them for us, but installing the dependencies manually made the issues go away.
我必须安装并链接 findup-sync 和其他一些 npm 包才能解决这些依赖问题。我虽然 npm 应该为我们处理它们,但是手动安装依赖项使问题消失了。
npm install findup-sync -g
npm install findup-sync -g
npm link findup-sync
npm link findup-sync
回答by Syn
This is because npm doesn't set the right permission to sub-directory node_modules in /usr/lib/node_modules/grunt-cli. In my case, I had:
这是因为 npm 没有为 /usr/lib/node_modules/grunt-cli 中的子目录 node_modules 设置正确的权限。就我而言,我有:
drwxr-x--- 6 nobody root 4096 16 févr. 17:08 node_modules
When running grunt as non-root user, I had the same error (Cannot find module 'findup-sync') because of a permission denied to read this directory.
当以非 root 用户身份运行 grunt 时,由于读取此目录的权限被拒绝,我遇到了同样的错误(找不到模块“findup-sync”)。
The solution is to fix permission with chmod: chmod a+rx node_modules.
解决方案是使用 chmod 修复权限:chmod a+rx node_modules。
But in fact, all directories was involved. The best way was to todo:
但实际上,所有目录都涉及。最好的方法是做:
find /usr/lib/node_modules/grunt-cli -type d -exec chmod a+rx {} \;
This is maybe a distribution bug (I use Archlinux).
这可能是一个分发错误(我使用 Archlinux)。
回答by inostia
This may seem simple, but if anyone else is unsure if there's a permissions problem, try running sudo gruntthen go from there.
这可能看起来很简单,但如果其他人不确定是否存在权限问题,请尝试运行sudo grunt然后从那里开始。
回答by rwreed
This also may be obvious, but in my case I had set up my npm path off my home directory (on a chromebook) and needed to add .node_modules to my .profilePATH=~./node_modules:$PATH
Then run:source ~/.profile
这也可能很明显,但在我的情况下,我已经在我的主目录(在 Chromebook 上)设置了我的 npm 路径,并且需要将 .node_modules 添加到我的 .profilePATH=~./node_modules:$PATH
然后运行:source ~/.profile
回答by aimadnet
I was able to fix this by reinstalling Grunt using these commands:
我能够通过使用以下命令重新安装 Grunt 来解决此问题:
sudo npm remove -g grunt-cli
sudo npm install -g grunt-cli
回答by tuliomir
I use NVM and was having this problem whenever I changed the active node version.
我使用 NVM 并且每次更改活动节点版本时都会遇到此问题。
Following @davidcondrey 's suggestion worked for me. The catch really was to install grunt-cli beforegrunt. The order made a difference and fixed it.
遵循@davidcondrey 的建议对我有用。真正的问题是在 grunt之前安装 grunt-cli 。订单有所不同并修复了它。
npm i -g grunt-cli grunt
@inostia 's answer of using sudoto test the permissions was OK, but gave me quite a headache with file permissions, as all the grunt-processed files were inacessible by git later and broke my versioning.
@inostia 使用sudo测试权限的答案是可以的,但让我对文件权限感到非常头疼,因为所有经过 grunt 处理的文件后来都无法被 git 访问并破坏了我的版本控制。
回答by MIkee
Tried all the answers above and I could not get grunt to work without using sudo
尝试了上面的所有答案,如果不使用 sudo,我就无法咕噜咕噜地工作
Finally came across this Wordpress articleand deleted the link to /usr/local/lib/node_modules/grunt/bin/grunt
终于看到这篇 Wordpress 文章并删除了指向/usr/local/lib/node_modules/grunt/bin/grunt
lrwxrwxrwx 1 root root 35 Apr 19 22:45 /usr/local/bin/grunt -> ../lib/node_modules/grunt/bin/grunt
using sudo rm /usr/local/bin/grunt
使用 sudo rm /usr/local/bin/grunt
Then I linked to the grunt executable in /usr/local/lib/node_modules/grunt-cli/bin
然后我链接到 /usr/local/lib/node_modules/grunt-cli/bin 中的 grunt 可执行文件
using sudo ln -s /usr/local/lib/node_modules/grunt-cli/bin/grunt /usr/local/bin/grunt
使用 sudo ln -s /usr/local/lib/node_modules/grunt-cli/bin/grunt /usr/local/bin/grunt
Now, I can run grunt without using sudo
现在,我可以在不使用 sudo 的情况下运行 grunt
回答by Gangadhar JANNU
This issue occurs if you change your NodeJSversion.
如果您更改NodeJS版本,则会出现此问题。
After changing the node version, re installing gruntor npm installwill resolve the issue.
更改节点版本后,重新安装grunt或npm install将解决问题。

