简体   繁体   English

从 package-lock.json 创建 package.json

[英]Create package.json from package-lock.json

I downloaded a theme and it has a package-lock.json file but no package.json file.我下载了一个主题,它有一个 package-lock.json 文件,但没有 package.json 文件。 Is there a way I can generate the package.json from the package-lock.json file.有没有办法可以从 package-lock.json 文件生成 package.json。 How do I install the node modules with just the package-lock.json file.如何仅使用 package-lock.json 文件安装节点模块。 Is there a way to do that?有没有办法做到这一点?

Warning: Do not attempt before reading comments below & backup package-lock.json.警告:在阅读下面的评论和备份 package-lock.json 之前不要尝试。

Install the latest npm with npm install -g npm使用npm install -g npm

Run npm init and respond to the questions.运行npm init并回答问题。

The above command will generate a package.json and include the existing packages listed in package-lock.json上述命令将生成一个package.json并包含package-lock.json中列出的现有包

I think I figured it out.我想我想通了。

I don't think npm init can draw from package-lock.json.我不认为npm init可以从 package-lock.json 中提取。 However it does seem to pull from what is already in your /node_modules .但是,它似乎确实从您/node_modules中已有的内容中提取。 I believe this is why @Harry B's solution works for some and not at all for others.我相信这就是为什么@Harry B 的解决方案适用于某些人而不适用于其他人的原因。

For example, if you have just cloned your project which contains package-lock.json, no package.json, and empty/non-existence node_modules, npm init won't create any dependencies.例如,如果您刚刚克隆了包含 package-lock.json、没有 package.json 和空/不存在的 node_modules 的项目, npm init不会创建任何依赖项。 However, if you run npm install pkg1 pkg2 pkg3 ... then run npm init it will create the dependencies in package.json.但是,如果您运行npm install pkg1 pkg2 pkg3 ...然后运行npm init它将在 package.json 中创建依赖项。

https://pravnyadv.github.io/unpackage/ seems to work. https://pravnyadv.github.io/unpackage/似乎有效。 Copy your package lock file text in, hit the button, copy out the text into a new package.json file.复制你的包锁定文件文本,点击按钮,将文本复制到一个新的 package.json 文件中。

package-lock.json file relies on the presence of a package.json file, So it's not possible to retrieve package.json (happy to be proved wrong). package-lock.json文件依赖于package.json文件的存在,因此无法检索package.json (很高兴被证明是错误的)。

So a possible solution left is to use a module like auto-install which is capable of generating package.json from the project file dependencies.所以剩下的一个可能的解决方案是使用像auto-install这样的模块,它能够从项目文件依赖项中生成package.json

First, you need to install the module globally npm install -g auto-install .首先,您需要全局安装模块npm install -g auto-install Then run npm init and answer the basic requirements.然后运行npm init并回答基本要求。

Then, run auto-install in your project root directory.然后,在项目根目录中运行auto-install All the dependencies should reflect in package.json file.所有依赖项都应反映在package.json文件中。

** **

Or Install node modules directly from package-lock.json或者直接从 package-lock.json 安装节点模块

** **

Run npm ci which bypasses a package's package.json to install modules from a package's lockfile.运行npm ci绕过包的 package.json 以从包的锁定文件中安装模块。

More Information 更多信息

暂无
暂无

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

相关问题 有没有办法从 package-lock.json 中提取 package.json? - Is there a way to extract package.json from package-lock.json? npm从package-lock.json文件中创建一个package.json文件? - npm to create a package.json file out of the package-lock.json file? Whats difference between package-lock.json and package.json, when is package.json generated? - Whats difference between package-lock.json and package.json, when is package.json generated? 从package-lock.json获取库 - Get Libraries from package-lock.json 如何使用 npm 将 package-lock.json 和/或 package.json 中的包版本更新到最新版本? - How to update version of a package in package-lock.json and/or package.json using npm to latest version? 什么是package-lock.json? - What is package-lock.json? 升级React库版本:建议只推送package.json还是同时推送package.json和package-lock.json? - Upgrading React library version: is it advisable to push only package.json or to push package.json and package-lock.json both? 如何为节点 js 项目重新生成 package.json 和 package-lock.json 文件? - How to regenerate a package.json and package-lock.json file for a node js project? npm-force-resolutions 是否会破坏 package.json 和 package-lock.json 之间的同步? - Does npm-force-resolutions break the sync between package.json and package-lock.json? 是否有工具可以验证/检查 package.json 和 package-lock.json 是否一致? - Is there a tool to validate/check that package.json and package-lock.json are consistent?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM