Gatsby: Remove one of package-lock.json and yarn.lock on gatsby new

Created on 8 Apr 2019  路  7Comments  路  Source: gatsbyjs/gatsby

Our starters currently include both package-lock.json and yarn.lock

This typically leads to some confusion due to yarn's warning (https://github.com/gatsbyjs/gatsby/issues/4514#issuecomment-458729956)

package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.

And in worst case, inconsistencies between the two, leading to issues like https://github.com/gatsbyjs/gatsby/issues/13194

Potential solution

It'd be nice to remove both lock files altogether but we can't because of https://github.com/gatsbyjs/gatsby/issues/10607#issuecomment-450290701

We could聽remove yarn.lock from the starter repositories and run yarn import if yarn is detected (this solves inconsistencies in the starter itself as well as inconsistencies _after_ the project is created if both files are still present like in https://github.com/gatsbyjs/gatsby/issues/13194)

What do you think @DSchau @KyleAMathews?

help wanted

Most helpful comment

The real long-term solution here is to ask people which client they use on their first gatsby new and then use that in the future.

All 7 comments

@JacobBlomgren Want to take a stab at this?

Just remembered that we added @renovate[bot] and it'll handle updates to both package-lock.json and yarn.lock. And we only track package-lock.json in git, yarn.lock is created via yarn import in CI thanks to @DSchau

So all we really need to do is, during gatsby new

  • Check if yarn is installed
  • If it is, remove package-lock.json
  • If it is not, remove yarn.lock

The remove operations should not fail if the file doesn't exist (since starters from the community could contain one or two or none)

We could also prompt, but since we internally use yarn currently if it is available (https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-cli/src/init-starter.js#L16-L28), we should just consistently do that for now

  • Check if yarn is installed
  • If it is, remove package-lock.json
  • If it is not, remove yarn.lock

Just to clarify: the check should be "if should use yarn" ( shouldUseYarn function that was linked by @sidharthachatterjee in previous comment) and not direct check if yarn is installed.

The real long-term solution here is to ask people which client they use on their first gatsby new and then use that in the future.

Regarding of your discussion I made a first implementation that seems to solve this issue. I used prompts to ask user which package manager he wants to use then remove the unwanted lock file.

Should I close this ?

Yeah this has been resolved so I'll close it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

theduke picture theduke  路  3Comments

ferMartz picture ferMartz  路  3Comments

Oppenheimer1 picture Oppenheimer1  路  3Comments

3CordGuy picture 3CordGuy  路  3Comments

timbrandin picture timbrandin  路  3Comments