react-nativegitlabgitlab-cigitlab-ci-runnerreact-native-native-module

yarn install in gitlab ci runner creates error "The lockfile would have been modified by this install, which is explicitly forbidden."


I am working on

react-native 0.75.2
yarn 3.6.4
node 20

In my project, I have a native module dependency, which is located inside my project folder. My package.json looks like

"dependencies": { 
  ....,
  "react-native-my-native-mod": "file:native_modules/react-native-my-native-mod", 
}

In gitlab-runner, it is creating an error because in gitlab-ci.yml, I have script like

yarn install --immutable

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

and it shows checksum difference in my native module.

I am using .yarnrc.yml that looks like

nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-3.6.4.cjs

I guess, when the project is locally installed by yarn install, the module is installed from the location I have specified in package.json i.e. file:native_modules/react-native-my-native-mod

But gitlab-runner is trying to install the module from builds folder i.e.

file:builds/0/project-0/native_modules/react-native-my-native-mod

As a result, the checksum is changed and it creates the above-mentioned error.

Or maybe some other reason behind it.

How to solve this?


Solution

  • Ideally, you'd figure out why yarn ends up with a different package checksum in the CI environment, and then fix the cause so yarn.lock isn't modified in the first place. That might be difficult, though 😄 (other people are reporting similar issues with no solution so far, e.g. here).

    As a workaround, you could explicitly update the checksum/hash for your (well-known/trusted) local package before running yarn install --immutable, e.g. like this:

    yarn up react-native-my-native-mod@file:native_modules/react-native-my-native-mod
    

    After that, your install shouldn't fail anymore under normal circumstances, but will still fail if any other checksum mismatch occurs.