0

I'm working on this project under a tight schedule and I have this error, below is a summary of how I got this error.

  • Working on Weatherme for viewing the weather location (my first actual implementation of APIs with Vue.js 3)
  • Got tired of the old design and decided to move to TailwindCSS - my definition of a sweet library
  • Made a new branch migrate-design-tailwind to push to GitHub
  • I recently switch to the default branch (main) to get a copy of a piece of functionality.

The issue is when I check the package.json file in Visual Studio Code, it tells me certain packages are not available (not a problem right)

So I re-installed the packages and the errors go away. That was the first time. The second time the same dependencies weren't found. This is a sample of my .gitignore

# Node modules
/node_modules

# Project logs
/logs

# Other stuff, don't look here
todo.txt
tailwind.full.config.js

The checkout command I used is git checkout main

Code can be found here

  • `.gitignore` isn't used by `git checkout` at all. The purpose of the file is to prevent files from being added by `git add` and to tell `git status` to ignore them as untracked files. `git` also doesn't know or care about what `node` packages are installed; it simply keeps track of changes to the file `package.json` that *`node`* uses to manage the environment. – chepner Dec 31 '21 at 20:06
  • This means that I always have to install the packages after every checkout, right? – Oyedeji Oyewole Dec 31 '21 at 20:11
  • Yes, because the packages themselves are not part of the repository, only the file that tells `node` what packages to install. – chepner Dec 31 '21 at 22:29
  • @chepner happy new year – Oyedeji Oyewole Jan 01 '22 at 00:26

2 Answers2

1

After you check out your code you need to do npm install, more or less every time. If you make sure your package-lock.json is checked in and restored when you check out your code, you'll install a reproducible set of packages.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
0

I found a library called husky, which can be found on npm or yarn which helps in the process of adding git hooks to a project.

Installation is pretty simple for npm users - $ npx husky-init && npm install Installation differs for yarn users

$ npx husky-init && yarn              # Yarn 1
$ yarn dlx husky-init --yarn2 && yarn # Yarn 2

I could get the checkout hook in my project easily using the command

$ npx husky add .husky/post-checkout "npm install"

I found all the hooks for git at this site

Happy New Year ✌