Search code examples
npmyarnpkg

how to convert package-lock.json to yarn.lock?


I have an project with package-lock.json file.

Now, I want to generate yarn.lock file based on package-lock.json file or existed node_modules of project.

How can I do this? thanks.


Solution

  • You can use yarn import to generate yarn.lock file from an existing npm-installed node_modules folder.

    yarn import aims to alleviate this challenge by generating a yarn.lock file in one of two ways:

    1. Using the dependency tree in an existing package-lock.json file created by npm install
    2. If no such file exists, using the versions found inside node_modules according to normal require.resolve() resolution rules.

    For example:

    ☁  api [develop] ⚡  yarn import   
    yarn import v1.17.3
    info found npm package-lock.json, converting to yarn.lock
    warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > left-pad@1.3.0: use String.prototype.padStart()
    success Saved lockfile.
    ✨  Done in 21.56s.