Viki 写东西的地方


How to ensure always installing the latest version when frequently publishing npm packages

In some extreme cases, it may be necessary to frequently publish npm packages, and the default caching time for npm is 5 minutes. This means that within five minutes, only one request for the metadata of the npm package will be made. If you publish again within five minutes after an update, the new version will not be detected by default.

In this case, if you use ncu (npm-check-updates package) to update the packages in package.json to the latest version, due to npm's cache, executing npm i will display an error of not being able to find the specified version of the target npm package, resulting in a failed update.


Use the --prefer-online flag

When executing npm install or npm update, add the --prefer-online flag to prioritize fetching from the remote registry.

npm install --prefer-online xxx

To apply the prefer-online setting to the project scope, you can add the following setting to the .npmrc file in the project's root directory:


Similar options include --prefer-offline, and the --cache-max=0 option is actually an alias for --prefer-online. For more information about npm config, please refer to the npm doc.

Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.