gitgithubgitlab

Auto-merging package-lock.json


git merge --no-ff account-creation

Auto-merging package-lock.json CONFLICT (content): Merge conflict in package-lock.json Automatic merge failed; fix conflicts and then commit the result.

Any idea regarding this issue ?


Solution

  • Sidenote: The "need" to enable auto merging can be avoided if the entire dev teams uses:

    npm ci
    

    instead of npm install as the default command to get a project up and running.

    npm install may mutate the package-lock.json, npm ci is read-only (and fails if package.json and package-lock.json are out of sync).


    If you want to automatically want to merge the lock file, as per the docs:

    Resolving lockfile conflicts

    Occasionally, two separate npm install will create package locks that cause merge conflicts in source control systems. As of npm@5.7.0, these conflicts can be resolved by manually fixing any package.json conflicts, and then running npm install [--package-lock-only] again. npm will automatically resolve any conflicts for you and write a merged package lock that includes all the dependencies from both branches in a reasonable tree. If --package-lock-only is provided, it will do this without also modifying your local node_modules/.

    To make this process seamless on git, consider installing npm-merge-driver, which will teach git how to do this itself without any user interaction. In short: $ npx npm-merge-driver install -g will let you do this, and even works with pre-npm@5.7.0 versions of npm 5, albeit a bit more noisily. Note that if package.json itself conflicts, you will have to resolve that by hand and run npm install manually, even with the merge driver.