0

I am an amateur developer and code some applications for home use. I use the Quasar framework for the front and Python for the back.

I have a git repository where master holds my "production code" and I would like to try the new version of Quasar (which uses Vue 3).

My principal concern is about how to deal with the new dependences this new framework will bring.

The framework is bootstrapped through quasar create testvue3 --branch next, which does all kinds of magical things, including installing npm libraries.

My understanding is that these libraries go into node_modules, which is not checked in (it is in .gitignore).

My question: how should I switch between the master and v2 branch (the one I will re-bootstrap my frontend on) when it comes to dependencies?

  • should I check in node_modules?
  • or npm install when switching branches?
  • or something else?

Note: Should "node_modules" folder be included in the git repository was suggested as a duplicate. While it has very useful information, it does not answer my question on how to deal with different branches (specifically how to switch between them and recover the right environment, library-wise)

WoJ
  • 27,165
  • 48
  • 180
  • 345
  • I believe [this](https://stackoverflow.com/q/18128863/1505348) post should help you out understanding the purpose of that directory. It should be check into git and run `npm I` when changing the active branch (although it will only install dependencies when needed). – Lucio Feb 06 '21 at 19:23
  • @Lucio: thanks, this is valuable information but does not actually address my question about how to switch branches (though it helps with the decision about whether to check `node_modules` in or not) – WoJ Feb 06 '21 at 19:28

1 Answers1

4

Different branches may contain different content for the package.json, either more/less dependencies or another version for the same ones. Therefore, when checking another branch is important to run npm install to make sure the required dependencies are installed on your local environment. In case that no change is detected the output of install command will return that nothing has been changed. The IDE may even help you out and suggest to run it only when needed as it is the case for WebStorm. To consider:

  1. Check package.json and package-lock.json into Git but not node_modules (it's huge!)
  2. When adding a dependency make sure to git commit all the changes to these two files
  3. Whenever a branch is changed run npm install to make sure dependency requirements are met
Lucio
  • 4,753
  • 3
  • 48
  • 77