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
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?
@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
yarn is installedpackage-lock.jsonyarn.lockThe 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
yarnis 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.
Most helpful comment
The real long-term solution here is to ask people which client they use on their first
gatsby newand then use that in the future.