npmazure-devopsyarnpkgyarn-workspacesyarn-lock.json

Facing issue while upgrading yarn 1.22.x to 3.8.3 in azure build pipeline


I need to upgrade yarn 1.22.x to 3.8.3 in azure build pipeline. I have modified the pipeline yml file:

 - task: NodeTool@0
        inputs:
            versionSpec: '16.x'
            checkLatest: true   
      script: corepack enable && yarn set version 3.8.3 && yarn install --network-timeout=1000000 --frozen-lockfile 
        displayName: Install dependencies
      - pwsh: |
            # yarn nx reset # Resets cache and nx daemon
            yarn nx run-many --target=build --configuration production --projects="my-app"
        displayName: Build

While running the build in azure devops pipeline I am getting below error

The lockfile would have been modified by this install, which is explicitly forbidden.

enter image description here


Solution

  • I can reproduce the issue using your yaml. The reason of the issue is that the yarn.lock isn't updated when running yarn install.

    To resolve this issue, follow the steps below to create a new yarn.lock file:

    1. Clone your repo on your local machine. git clone <your repo url>
    2. Delete yarn.lock from your project.
    3. Run corepack enable, yarn set version 3.8.3 and yarn install in the root folder of your project.
    4. A new yarn.lock file will be created automatically. Push it into your Azure Repo. Then your pipeline should work as expected.

    If you don't want to update the yarn.lock file in Azure repo and just want to upgrade yarn in the current pipeline, remove --frozen-lockfile from your command, add an environment variable YARN_ENABLE_IMMUTABLE_INSTALLS and set its value to false. Then the pipeline will work.

    - task: NodeTool@0
      inputs:
        versionSpec: '16.x'
      displayName: 'Install Node.js'
    - script: |
        corepack enable
        yarn set version 3.8.3
        yarn install --network-timeout=1000000 
      env:
        YARN_ENABLE_IMMUTABLE_INSTALLS: false
    

    You can see the same issue here for more details.