我刚删除了node_modules,如何重新安装它们?

时间:2018-04-03 02:39:44

标签: node.js mongoose npm

最初我只是想尝试运行一个演示应用来练习猫鼬。应用程序cats.js不会与节点一起运行,因为我会收到此错误:

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)

不幸的是,。/ timestamp模块出现在错误中列出的所有位置。

我阅读How do I resolve "Cannot find module" error using Node.js?尝试修复它并最终运行“rm -rf node_modules”,删除了所有node_modules。当我尝试使用“npm install”重新安装时,我收到了以下错误:

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.

我没有看到关于这两个错误的任何答案。

我的首要任务是重新安装npm。我的第二个优先事项是找出我在尝试运行cats.js时收到的原始错误,但我可以为此创建一个新问题。

2 个答案:

答案 0 :(得分:1)

发生的事情是你有一个依赖于另一个模块作为对等依赖的模块。创建对等依赖项以解决插件问题。有关更多信息,请查看这些帖子; npm peer dependeciesunderstanding the npm dependecy model

如果您已经运行npm install并且出现此错误,则表明您没有安装jquery@1.9.1popper.js@^1.12.9并将其保存到package.json

要摆脱这种情况,您应首先手动安装它们,然后再次运行npm install。试试这个;

rm -r node_modules
npm install jquery@1.9.1 --save
npm install popper.js@^1.12.9 --save
npm install

答案 1 :(得分:0)

在您之前的安装过程中 node_modules,如果启用了保存标记,则所有这些模块必须在package.json的{​​{1}}对象中包含一个条目。

在这种情况下,只需对dependenciesnpm i次,并重新安装之前的每个模块。

如果您的npm install package.json对象中没有任何内容,那么您需要通过指定模块名称再次安装每个模块,这次需要&# 39;忘记提及dependencies旗帜。

刚开始做--save

如果你发现写npm i dep-1 dep-2 ... --save有点筋疲力尽,那就在你的资料库中做一次。

--save

这将为您将在此处安装的每个依赖项启用save标志。

相关问题