简体   繁体   English

为现有项目创建/更新package.json

[英]Create/update package.json for existing project

I have a NodeJS project that was started long ago. 我有一个很早就开始的NodeJS项目。 It has many packages that were installed before I understood the --save flag. 在我了解--save标志之前,它已经安装了许多软件包。 A few versions ago npm decided that it would delete packages that are not mentioned in package.json (an insane thing to do). 几个版本之前,npm决定删除package.json中未提及的软件包(这是一件疯狂的事情)。 This causes a terrible problem. 这导致了一个可怕的问题。

Now I understand --save and use it properly. 现在我了解了-保存并正确使用它。 However, I cannot figure out a way to update package.json with packages that are not listed. 但是,我无法找出一种使用未列出的软件包更新package.json的方法。

Is there some way to cause npm or some other program to look at a project and add missing dependencies? 有什么方法可以使npm或其他程序查看项目并添加缺少的依赖项? I'd be happy enough if it completely recreated the dependency structure. 如果它完全重新创建了依赖关系结构,我会很高兴。

Suggestions? 建议?

UPDATE : npm 3.5+ 更新:npm 3.5+

Remove everything from package.json and run: npm init --yes . 从package.json中删除所有内容,然后运行: npm init --yes

This will recreate the package.json with dependencies, but not the devdependencies. 这将重新创建具有依赖关系但不具有devdependencies的package.json。

npm 3 npm 3

If your're on Unix based systems, from inside your project root folder, with a package.json file already created (npm init, as you mentioned), run: 如果您使用的是基于Unix的系统,请从项目根文件夹内部,并已创建一个package.json文件(如前所述,为npm init),运行:

npm install $(ls node_modules/) --save

and it will reinstall the packages, and save them into package.json as dependencies 它将重新安装软件包,并将其作为依赖项保存到package.json中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM