Skip to content

Install without package.json #4813

Closed
Closed

Description

@ronag

For docker builds it would be nice to be able to run yarn with only the lock file, i.e. without the package.json file. Currently, whenever we run npm version patch we have to re-install all dependencies even though nothing has changed... :/

Activity

  1. BYK commented on Nov 1, 2017

    @BYK
    Member

    Yarn needs both package.json and yarn.lock files by design and I don't think that will change anytime soon if ever.

    I think instead of copying all files in the directory, you can find a way to leverage Docker's layered file system with selectively copying files over.

  2. ronag commented on Nov 1, 2017

    @ronag
    Author

    @BYK I don't see anyway to resolve this otherwise? Since the package.json is changed during versioning and it has to be included before you run yarn you always have to re-install all dependencies even if they haven't changed...

  3. stillward commented on Apr 17, 2019

    @stillward

    May be using another file to save the version, like VERSION. use semver -i patch <version> to generate the new version and use fs.writeFileSync to save it to VERSION file

  4. Downchuck commented on Jun 25, 2019

    @Downchuck

    This is an awful experience when using offline workspaces with Docker as the primary yarn.lock does contain information for unpacking files.

  5. sebmellen commented on Feb 7, 2021

    @sebmellen

    @BYK and @ronag and @Downchuck have any of you found a way to resolve this yet?

    I'm into doing the same thing as I'm using yarn workspaces, and otherwise I have to pull in and concatenate dependencies from the package.json files in each submodule I've added to my project. If I could just install from yarn.lock which is in the top-level directory and lists all the hoisted packages of all the submodules, I could just copy that over to the base Docker layer and save myself the trouble...

    Kinda stumped looking for ways around this.

  6. psigen commented on Oct 19, 2022

    @psigen

    @sebmellen @Downchuck @ronag: FWIW, this is specifically addressed in pnpm, which adds a command called pnpm fetch to do this exact thing for this exact purpose (and is specifically cited for docker builds):

    https://pnpm.io/cli/fetch

  7. rohit-gohri commented on Jan 7, 2023

    @rohit-gohri

    I created a small helper for yarn berry (v2+) inspired by pnpm's fetch that recreates the workspace just from the lockfile so yarn can do a successful install - https://github.com/rohit-gohri/yarn-lock-to-package-json

    COPY .yarn ./.yarn
    COPY yarn.lock .yarnrc.yml ./
    
    RUN yarn dlx yarn-lock-to-package-json
    
    RUN yarn install --immutable
    

    This means docker layer cache is not invalidated due to random changes in package.jsons

  8. sod commented on Mar 2, 2023

    @sod

    Thats a clever sollution @rohit-gohri, and also kinda proves that requiring the package.jsons for yarn install --immutable is arbitrary if you are able to generate what yarn wants from the lockfile.

    I wonder if doing this as a plugin instead would be possible.

  9. rohit-gohri commented on Mar 2, 2023

    @rohit-gohri

    I wonder if doing this as a plugin instead would be possible.

    @sod I tried doing it but could not figure out yarn internals 😅 , this way ended up being easier. There is a issue in yarn v2+ where the author tried implementing a plugin - yarnpkg/berry#4529

  10. devthejo commented on Apr 12, 2023

    @devthejo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions