I am working on a project that is currently using Gatsby v2 in it's package.json file. However, in order to run the project I need Gatsby-cli install globally as per docs. But this also seems to install gatsby v4 globally and it appears my project is trying to use the Gatsby v4 global install instead of the v2 from package.json.
I have tried running npm i -g gatbsy-cli@2 which seems to install gatbsy-cli v2 but gatsby v4.
Similarly running npm i -g gatsby@2 doesn't override the v4 global install
Package.json
{
...
"dependencies": {
"gatsby": "^2.29.0",
...
}
}
$ gatsby -v
Gatsby CLI version: 2.19.3
Gatsby version: 4.4.0
Note: this is the Gatsby version for the site at: /path/to/project
Your gatsby-cli seems to be in the proper version, however, gatsby package needs to be in a specific version in your project, not globally as you are trying to do in:
npm i -g gatsby@2
Try removing your package-lock.json and run:
npm i gatsby@2