I need to generate a yarn.lock
file from my package.json
but I want to avoid node_modules
creation. Is it possible?
Whenever you run yarn (which is the equivalent of running yarn install ) upon a fresh install, a yarn. lock file is generated. It lists the versions of dependencies that are used at the time of the installation process. That means it looks into your package.
Managed by Yarn lock file is auto-generated and should be handled entirely by Yarn. As you add/upgrade/remove dependencies with the Yarn CLI, it will automatically update your yarn.
yarn install is used to install all dependencies for a project. The dependencies are retrieved from your project's package. json file, and stored in the yarn. lock file.
Every project using yarn should commit the yarn lockfile to source control. The lockfile is the source of truth for telling other developers how to install dependencies for your project. Without this lockfile, other developers will be at risk for installing the wrong packages.
EDIT: Please check the comment below for a solution without the need for any additional package thanks to @talon55 : npm install --package-lock-only; yarn import
Old answer:
This is actually one of the few features that NPM has (npm install --package-lock-only
) and Yarn does not support.
It is a heavily requested feature as you can tell from these 2 open Github issues: 5738 and 2340
I stumbled upon the command yarn generate-lock-entry
documented in here but it definitely does not do what we are looking for.
The workaround I would suggest is generating an NPM lock file and converting it to a yarn.lock
file using synp:
npm install -g synp npm install --package-lock-only synp --source-file package-lock.json
Please note that Synp requires the the packages to be installed and that the node_modules is rightly populated. This may, or may not be, a problem to your use case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With