Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to generate a `yarn.lock` file without installing the packages?

Tags:

I need to generate a yarn.lock file from my package.json but I want to avoid node_modules creation. Is it possible?

like image 297
ciaoben Avatar asked Jun 08 '17 14:06

ciaoben


People also ask

What generates a yarn lock file?

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.

Is yarn lock automatically generated?

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.

Does yarn install use lock file?

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.

Does yarn need 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.


1 Answers

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.

like image 189
Anas Tiour Avatar answered Sep 30 '22 19:09

Anas Tiour