Using the Git checkout command can ignore the folders specified in the .gitignore file

Working on a project with tight deadlines, I encountered an error. Here is how it all unfolded:

  • Started working on Weatherme to display weather data (my first time using APIs in Vue.js 3)
  • Decided to switch from the old design to TailwindCSS - my favorite CSS library
  • Created a new branch migrate-design-tailwind and pushed changes to GitHub
  • Switched back to the default branch (main) to get some code functionality

The problem arose when checking the package.json file in Visual Studio Code, showing missing packages.

I re-installed the packages to resolve the issue temporarily, but the same dependencies were missing again later. Here is a snippet from my .gitignore

# Node modules
/node_modules

# Project logs
/logs

# Miscellaneous files
todo.txt
tailwind.full.config.js

Using the command git checkout main to switch branches

View the code here

Answer №1

Don't forget to run the npm install command after checking out your code. It's important for maintaining a consistent set of packages in your project. Make sure to include and restore your package-lock.json file when committing changes to ensure reproducibility.

Answer №2

Stumbling upon a tool called husky, I discovered it on npm and yarn. It simplifies the process of adding git hooks to a project.

For npm users, installation is as easy as running

$ npx husky-init && npm install
. However, yarn users have a slightly different installation procedure.

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

Adding the checkout hook to my project was a breeze with this command:

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

I came across a comprehensive list of git hooks at this site.

Cheers to a Happy New Year! ✌

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When attempting to run the yarn build dist command, an error of type TypeError is encountered, stating that it is not possible to set the constructor property

Upon executing the following command in a GitHub workflow, I encountered this error: npm-run-all -p types transpile @internal_package: $ swc src --out-dir dist @internal_package: /home/runner/work/repo-name/repo-name/node_modules/ttypescript/lib/loadTypesc ...

Whenever I publish, my npm package transitions to a private status

My npm organization (which I pay for) contains a few private packages. However, there is one particular package that should be public. It was previously set as private. Lately, whenever I try to publish it, the package reverts back to being private, and I ...

Encountering an Uncaught TypeError due to failure to read the property 'bool' of an undefined value

Encountering a runtime error in my code that I can't seem to pinpoint. Everything was functioning correctly before this error surfaced after updating npm. Here's the error message: Uncaught TypeError: Cannot read property 'bool' of und ...

Having difficulty executing the command 'npm install -g expo-cli'

When attempting to execute npm install - g expo-cli on a Windows 10 machine, I am encountering issues. An error message keeps popping up and preventing me from proceeding. I'm in desperate need of assistance! npm WARN deprecated <a href="/cdn-cgi/ ...

Having trouble getting Vue.js to cooperate with a brand new Laravel 5.8 setup?

I set up a fresh Laravel project using laravel new sample. Then I executed npm install followed by npm run dev. Next, I modified the welcome.blade.php file as shown below: <!DOCTYPE html> <html> <head> <script type="text/j ...

Achieve uninterrupted deployment of node.js applications by utilizing naught for zero downtime implementation

Recently, I began utilizing naught for deploying my node.js applications (https://github.com/andrewrk/naught). In my Ubuntu Server, I have a directory that contains my node.js (express) app. To deploy it, I used the command "naught start app.js" from tha ...

Master the art of building custom ReactJS applications with a targeted focus

Is it possible to develop a react application with a specific range? This method: npx create-react-app web1 generates this package.json: { "name": "web1", ..... } I am interested in understanding how to create it with a particular ...

Trouble arises when attempting to Browserify build with a local version of an npm module listed in my package.json dependencies

After successfully setting up a package.json and bundling my app's dependencies with browserify, I encountered an issue when trying to replace one of the dependencies with a local forked copy, resulting in build failures. The following configuration ...

Does the presence of a package-lock.json file in a node module override or ignore the parent package-lock.json file?

Imagine you have a repository that contains various peer development dependencies. This particular repository serves as a standalone eslint configuration, similar to airbnb. If you were to utilize this repository in another project as a node module by imp ...

Unable to transition from webpack version 3 to 3.12.0

Is there a way to resolve an issue with a node package that demands a higher version of webpack than what is currently installed on my system? You can find my packages.json file here. Whenever I attempt to install the required package: npm install <a ...

Dependencies for Angular 5 plugins

Will the total list of dependencies for the application be a combination of all unique dependencies from Angular plugins with their own managed dependencies in Node, even if they have some overlapping dependencies? For example, if plugin 1 has 1000 depen ...

Retrieving information from a JSON object that includes arrays

I've been researching how to extract data from the response body of a server, but I haven't had much luck finding a solution that works for my https request returning a JSON object. //Initiate the request: request({ //Specify the request met ...

One of the essential components in Angular is currently absent

After integrating Angular4 with Visual Studio 2017 following the steps outlined in this article, I realized that my setup also involved using Nodejs 8.6.0 and npm 5.4.2 - which were the latest versions at the time. Despite having vs2017 generate a fold ...

Error in CentOS - The effective user ID is not 0. Have you properly installed sudo as setuid root?

After coming across a similar question with the same headline, I realized that my situation is slightly different. While setting up a new project, I encountered an issue with installing nodejs. It seemed to only work when using sudo, for example, sudo npm ...

Remove a package by utilizing npx

I am attempting to remove a package that I installed with the command: npx terminalgpt I have tried the following: npm uninstall -g terminalgpt However, this method is not successful. What is the correct way to uninstall this package? ...

There was a hiccup during the installation of expressjs through npm at the office

Recently, I've been eager to delve into node.js and express.js. After successfully installing node.js on my office system, I attempted to install express.js using the command 'npm install express --g', only to encounter an error. I even conf ...

What is the best way to silence deprecation warnings from npm/nvm in zsh?

I have incorporated nvm into my workflow to manage node versions by installing it as a plugin for zsh using zsh-nvm. Currently, I have two node versions installed - v6.1.0 and v0.10.42. As the project I am working on requires the latter version, I have set ...

Angular 2 release candidate 3 encounters issues with unfulfilled dependencies

Having encountered an issue with npm, specifically related to dependencies while using packages.json from the official Angular2 site's quick start guide. Yesterday everything was functioning correctly, but today I am facing difficulties as npm is unab ...

Error message "Module 'node:process' not found" occures while working with fastify-cli globally on Mac operating system

I recently set up a new Mac development machine and successfully installed node, npm, and nvm. Everything was working fine in one project directory until I tried to install and use fastify-cli and encountered the following error: internal/modules/cjs/loade ...

Begin by running the command to start a local http-server

After cloning angular seed, I found that it is using node's http-server and functioning flawlessly with the specified configuration. To start the server, simply run: npm start (from the root of the project) The necessary configuration can be found ...