简体   繁体   English

如何更新 package.json 和 package-lock.json 文件中的所有包?

[英]How can I update all the packages inside the package.json and package-lock.json files?

I have a website and I haven't updated it for about a year.我有一个网站,大约一年没有更新它。 I need to update all the packages in "package.json" and "package-lock.json" and I have no clue how to do it.我需要更新“package.json”和“package-lock.json”中的所有包,我不知道该怎么做。 I would be grateful for any suggestion.我将不胜感激任何建议。 The Node version I'm using is 16.15.1 LTS.我使用的 Node 版本是 16.15.1 LTS。

You can update packages in package.json with these steps:您可以通过以下步骤更新package.json中的软件包:

1- Navigate to the root directory of your project and ensure it contains a package.json file: 1- 导航到项目的根目录并确保它包含package.json文件:

cd /path/to/project

2- In your project root directory, run the update command: 2- 在您的项目根目录中,运行更新命令:

npm update

3-To test the update, run the outdated command. 3-要测试更新,请运行过时的命令。 There should not be any output.不应该有任何 output。

npm outdated

And for package-lock.json follow these steps:对于package-lock.json按照下列步骤操作:

1- Delete your package-lock.json file in the root directory of your project, 1- 删除项目根目录中的package-lock.json文件,

2- Simply run npm install as in default, it checks if your directory has package-lock.json file otherwise, it will create one for you. 2- 只需运行npm install ,它会检查您的目录是否有package-lock.json文件,否则,它会为您创建一个。 (This command will honour the ^ and ~ symbol and update the packages to its latest that is provided by the library author(s)). (此命令将尊重 ^ 和 ~ 符号并将软件包更新到库作者提供的最新版本)。

Information about ^ and ~:关于 ^ 和 ~ 的信息:

In package.json , a version can have a ^ in front (eg ^0.12.31), meaning the latest minor release may be safely installed.package.json中,版本可以在前面有一个^ (例如 ^0.12.31),这意味着可以安全地安装最新的次要版本。

Tilde (~) in front (eg, ~0.12.31) means the latest patch release is safe to install.前面的波浪号(~) (例如,~0.12.31)表示最新的补丁版本可以安全安装。

暂无
暂无

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

相关问题 如何使用 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? 无法下载所有 reactjs 包。 只获取 node_modules、package-lock.json 和 package.json - Not able to download all the reactjs packages. Only getting node_modules, package-lock.json and package.json 有没有办法从 package-lock.json 中提取 package.json? - Is there a way to extract package.json from package-lock.json? 从 package-lock.json 创建 package.json - Create package.json from package-lock.json 如何修复 package-lock.json 中未在 package.json 中列出的易受攻击的 npm 包? - How do I fix a vulnerable npm package in my package-lock.json that isn't listed in the package.json? 角度应用程序中需要 package.json 和 package-lock.json 文件 - Need for both package.json, package-lock.json files in an angular application 为什么`npm install`为同一个`package.json`文件生成不同的`package-lock.json`文件? - Why does `npm install` generate different `package-lock.json` files for the same `package.json` file? 有没有办法确认package-lock.json实际上解析了package.json中的所有依赖项? - Is there a way to confirm a package-lock.json actually resolves all dependencies in a package.json? 如何将容器内部生成的package-lock.json文件传递给源代码? - How can I pass to my source code the package-lock.json file generated inside my container? 如何处理 package-lock.json 中依赖项所需的过时包? - How to handle outdated packages that are required by a dependency in package-lock.json?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM