1

Initially I was just trying to run a demo app to practice mongoose. The app, cats.js, would not run with node because I would get this error:

module.js:540
throw err;
^

Error: Cannot find module './timestamp'
    at Function.Module._resolveFilename (module.js:538:15)
    at Function.Module._load (module.js:468:25)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/taylorlassiter/Desktop/visual_studio/yelp_camp/node_modules/bson/lib/bson/bson.js:6:15)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)

Unfortunately, the ./timestamp module appeared in all the places listed in the error.

I read How do I resolve "Cannot find module" error using Node.js? to try to fix it and ended up running "rm -rf node_modules" which removed all node_modules. When I tried to reinstall with "npm install", I get these errors:

npm WARN bootstrap@4.0.0 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.

npm WARN bootstrap@4.0.0 requires a peer of popper.js@^1.12.9 but none is installed. You must install peer dependencies yourself.

I haven't seen any answers regarding these two errors.

My first priority is getting npm reinstalled. My second priority would be to figure out the original error I was receiving when trying to run cats.js, but I can create a new question for that.

Renato Gama
  • 16,431
  • 12
  • 58
  • 92

2 Answers2

1

What is happening is that you have a module that depends on another as a peer dependency. Peer dependencies were created to solve a problem with plugins. Have a look at these posts for more information; npm peer dependecies and understanding the npm dependecy model

If you have ran npm install and got this error it seems that you don't have jquery@1.9.1 and popper.js@^1.12.9 installed and saved to you package.json

To get rid of this you should manually install them first, then run npm install again. Try this;

rm -r node_modules
npm install jquery@1.9.1 --save
npm install popper.js@^1.12.9 --save
npm install
Renato Gama
  • 16,431
  • 12
  • 58
  • 92
0

During previous installation of your node_modules, if the save flag was enabled then all those modules must be having an entry in your package.json's dependencies object.

In that case just do npm i short for npm installand every module that you earlier had will get reinstalled.

If there isn't anything in your package.json's dependencies object, then you need to install each of your module again by specifying the module name and this time don't forget to mention the --save flag.

Just start doing npm i dep-1 dep-2 ... --save.

If you find writing --save a little exhausting then just do this once in your repository.

npm config set save=true

This will enable save flag for each dependency you will install here onwards.

Himanshu Singh
  • 970
  • 2
  • 6
  • 18