cannot find module "lodash"

node.jsGulpGulp Sass

node.js Problem Overview


Today I tried to learn more about Google Web Starter Kit so I followed these instructions and 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:

C:\gwsk>gulp serve

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 Solutions


Solution 1 - node.js

Be sure to install lodash in the required folder. This is probably your C:\gwsk directory.

If that folder has a package.json file, it is also best to add --save behind the install command.

$ npm install lodash --save

The package.json file holds information about the project, but to keep it simple, it holds your project dependencies.

The save command will add the installed module to the project dependencies.

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:

$ 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.

Hope this helps you understand the node package manager a little bit more.

Solution 2 - node.js

I found deleting the contents of node_modules and performing npm install again worked for me.

Solution 3 - node.js

Maybe loadash needs to be installed. Usually these things are handled by the package manager. On your command line:

npm install lodash 

or maybe it needs to be globally installed

npm install -g lodash

Solution 4 - node.js

Reinstall 'browser-sync' :

rm -rf node_modules/browser-sync
npm install browser-sync --save

Solution 5 - node.js

If there is a package.json, and in it there is lodash configuration in it. then you should:

npm install

if in the package.json there is no lodash:

npm install --save-dev

Solution 6 - node.js

though npm install lodash would 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.

lodash is part of browser-sync. The best solution is the one provided by Saebyeok. Re-install browser-sync and that should fix the problem.

Solution 7 - node.js

For me, I update node and npm to the latest version and it works.

Solution 8 - node.js

The above error run the commend line\

please change the command $ node server it's working and server is started

Solution 9 - node.js

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.io if 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.

yarn install

yarn build --force

enter image description here

Yarn build --force execution: enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBosko SkrbinaView Question on Stackoverflow
Solution 1 - node.jsbohem.beView Answer on Stackoverflow
Solution 2 - node.jskernowcodeView Answer on Stackoverflow
Solution 3 - node.jsWill ShaverView Answer on Stackoverflow
Solution 4 - node.jsSaebyeokView Answer on Stackoverflow
Solution 5 - node.jsaircraftView Answer on Stackoverflow
Solution 6 - node.jsYoweli KachalaView Answer on Stackoverflow
Solution 7 - node.jsG.yxView Answer on Stackoverflow
Solution 8 - node.jsmaheshView Answer on Stackoverflow
Solution 9 - node.jsadityaView Answer on Stackoverflow