How to ignore node_modules?

Yoodley is reader-supported. When you buy through links on our site, we may earn an affiliate commission.

How to ignore node_modules?

The node_modules/ folder subdirectory contains all of the packages that are required by your JavaScript project and is where they are downloaded and installed. As a result, this folder is frequently rejected from a remote repository due to its vast size and the fact that you should not add code to the repository that you did not write.

You should instead include only those packages that are required by your project and ignore the node modules/ folder by including a .gitignore file in the root of your project’s repository instead of including the node_modules/ folder.

A .gitignore file is a plain text file in which you can provide a list of patterns for files or folders that Git should not track as part of your project’s files or folders. It is widely used to exclude auto-generated files from your project’s directory structure.

You only need to specify the folder name inside the node modules/ folder if you want to disregard the node modules folder.

gitignore file:

Your node modules/ folder subdirectory will now be ignored by Git as a result of this action.  This works even if you have numerous node_modules/ folders contained within other subfolders of the same folder structure.

How to ignore node_modules in vscode?

Method 1: Hide Node_modules vscode extension

Hide Node Modules is a fantastic small vscode module written by Chris Bibby that does exactly what you need it to. The plugin adds a right-click context menu action to your javascript/nodejs projects to show/hide the node module folder.

  • Click Extensions in vscode.
  • Look for “Hide Node Modules.”
  • Select the extension and press the “Install” button.
  • Return to File Explorer and right-click to select “Show/Hide Node Modules.

Method 2: Hide node_modules in .vscode/settings.json

  • Make a folder called.vscode in your project folder.
  • Make a settings.json file within.vscode (i.e..vscode/settings.json).
  • Insert the file.
  • Set the exclude setting to true if “**/node modules” is set to true.

Method 3: Hide node_modules in .code-workspace file

Except for the addition of the files, this procedure is nearly identical to method 2.

In a vscode workspace file, there is an exclusion setting. The Hide Node_modules addon employs this strategy behind the scenes.

 

<# ./myproject.code-workspace

{

    “folders”: [

        {

            “path”: “frontend”

        }

    ],

    “settings”: {

        “files.exclude”: {

 

            “**/node_modules”: true

        }

    }

}>

How to manually unhide node_modules?

If a folder/workspace is opened in VSCode without the Hide Node Modules extension but has previously been used to hide the node modules folder, VSCode will keep it hidden – the extension makes advantage of a setting in the VSCode settings. The visibility of the node modules subdirectory is controlled by a json file.

Without using the extension, unhide the node modules subdirectory as follows:

  • Open the settings.json file in the.vscode folder.
  • Within “files.exclude,” look for the line “**/node modules”: true.
  • Replace “**/node modules” with “false.”
  • Keep the file safe.
  • The node modules folder should now be accessible via the explorer.

LEAVE A REPLY

Please enter your comment!
Please enter your name here