I have a gatsby project which works perfectly fine. I just now copied the whole project (without the node-modules folder) and did a yarn install
because I wanted to test something. When I run the project however I get several errors. I just now checked one of them and it clearly is an error that needs fixing. I am calling a function doesn't exist anywhere.
I am wondering however why my initial project didn't throw any errors or warnings at the very least? It doesn't make sense to me and worries me. Any ideas why this could be?
Assuming the scenario you've described (cloned working project), the issue must come from different Node versions between them or due to some package versions conflict. You have several ways to fix it:
Adding a .nvmrc
file in your root project. You just need to add the current node version of the source project there. For example: 12.0.1
, Nothing else. This file will lock the Node versions and will use it in the cloned project. This is the cleanest and scalable way.
Manually changing the nvm
and running the Node version in your destination folder. Once you know your source project Node versions, you have to use nvm use VERSION_HERE
to your cloned project.
Keep in mind that after changing the Node versions, you must install again all your packages with yarn install
. Strongly recommended to remove .cache
folder too.
Let's say that your package.json
has a dependency like ^2.3
and in your source project, your dependency is at 2.31
for example. If you clone that project, after yarn install
, it may take another higher version rather than 2.31
. This may cause compilation errors due to conflicts between dependencies. The way to fix it is to clone your yarn-lock
too since it contains the locked current working versions of your project.