node.js 找不到模块“lodash”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27431187/
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 "lodash"
提问by Bosko Skrbina
Today I tried to learn more about Google Web Starter Kit so I followed these instructionsand after a lot of fight and problem I just tried to start a local server (the first task we'll look at is: $ gulp serve.) and received this error:
今天我试图了解更多关于 Google Web Starter Kit 的信息,所以我遵循了这些说明,经过大量的斗争和问题,我只是尝试启动本地服务器(我们要查看的第一个任务是:$ gulp serve.)并收到此错误:
C:\gwsk>gulp serve
C:\gwsk>gulp 服务
Error: Cannot find module 'lodash'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\gwsk\node_modules\browser-sync\node_modules\portsc
anner-plus\lib\index.js:3:9)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\gwsk\node_modules\browser-sync\lib\utils.js:6:19)
Honestly I'm completely lost here, so any help is pretty welcome. I'm new to node.js, to gulp, I just wanted it to try GWSK but turn into a headache :(... I'm a web designer not developer....
老实说,我完全迷失在这里,所以非常欢迎任何帮助。我是 node.js 的新手,大吃一惊,我只是想让它尝试 GWSK 但变得头疼:(...我是网页设计师而不是开发人员....
回答by bohem.be
Be sure to install lodash in the required folder. This is probably your C:\gwsk directory.
确保在所需的文件夹中安装 lodash。这可能是您的 C:\gwsk 目录。
If that folder has a package.json file, it is also best to add --save behind the install command.
如果该文件夹有 package.json 文件,最好在安装命令后面添加 --save 。
$ npm install lodash --save
The package.json file holds information about the project, but to keep it simple, it holds your project dependencies.
package.json 文件包含有关项目的信息,但为了简单起见,它包含您的项目依赖项。
The save command will add the installed module to the project dependencies.
save 命令会将已安装的模块添加到项目依赖项中。
If the package.json file exists, and if it contains the lodash dependency you could try to remove the node_modules folder and run following command:
如果 package.json 文件存在,并且它包含 lodash 依赖项,您可以尝试删除 node_modules 文件夹并运行以下命令:
$ npm cache clean
$ npm install
The first command will clean the npm cache. (just to be sure) The second command will install all (missing) dependencies of the project.
第一个命令将清理 npm 缓存。(只是为了确定)第二个命令将安装项目的所有(缺失)依赖项。
Hope this helps you understand the node package manager a little bit more.
希望这可以帮助您更多地了解节点包管理器。
回答by kernowcode
I found deleting the contents of node_modules and performing npm installagain worked for me.
我发现删除 node_modules 的内容并npm install再次执行对我有用。
回答by Saebyeok
Reinstall 'browser-sync' :
重新安装“浏览器同步”:
rm -rf node_modules/browser-sync
npm install browser-sync --save
回答by Will Shaver
Maybe loadash needs to be installed. Usually these things are handled by the package manager. On your command line:
也许需要安装loadash。通常这些事情由包管理器处理。在您的命令行上:
npm install lodash
or maybe it needs to be globally installed
或者它可能需要全局安装
npm install -g lodash
回答by aircraft
If there is a package.json, and in it there is lodashconfiguration in it. then you should:
如果有package.json, 并且里面有lodash配置。那么你应该:
npm install
if in the package.jsonthere is no lodash:
如果在package.json没有lodash:
npm install --save-dev
回答by G.yx
For me, I update node and npm to the latest version and it works.
对我来说,我将 node 和 npm 更新到最新版本并且它可以工作。
回答by aditya
I got the error above and after fixing it I got an error for lodash/merge, then I got an error for 'license-check-and-add' then I realized that according to https://accessibilityinsights.ioif I ran the below command, it installs all the missing pacakages at once! Then running the yarn build command worked smoothly with a --force parameter with yarn build.
我得到了上面的错误,在修复它之后我得到了 lodash/merge 的错误,然后我得到了“license-check-and-add”的错误然后我意识到根据https://accessibilityinsights.io如果我运行了在命令下面,它会立即安装所有丢失的包!然后运行纱线构建命令与纱线构建的 --force 参数一起顺利运行。
yarn install
yarn build --force
回答by mahesh
The above error run the commend line\
上述错误运行推荐行\
please change the command $ node serverit's working and server is started
请更改命令 $ node server它正在工作并且服务器已启动
回答by Yoweli Kachala
though npm install lodashwould work, I think that it's a quick solution but there is a possibility that there are other modules not correctly installed in browser-sync.
虽然npm install lodash可行,但我认为这是一个快速解决方案,但有可能在browser-sync.
lodash is part of browser-sync. The best solution is the one provided by Saebyeok. Re-install browser-syncand that should fix the problem.
lodash 是browser-sync. 最好的解决方案是 Saebyeok 提供的解决方案。重新安装browser-sync,应该可以解决问题。


