【问题标题】:Why is my node_modules folder greyed out after command 'npm install'?为什么我的 node_modules 文件夹在命令“npm install”后显示为灰色?
【发布时间】:2021-08-20 14:12:45
【问题描述】:

我想知道为什么在我运行命令npm install 后,我的 VS Code 编辑器中的 node_modules 文件夹是灰色的。

这是我文件夹的图片:

【问题讨论】:

    标签: visual-studio-code


    【解决方案1】:

    .gitignore 中包含的文件/文件夹显示为灰色。通常node_modules 文件夹包含在.gitignore 中。

    【讨论】:

      【解决方案2】:

      这是因为您的 node_modules 文件夹在您的 .gitignore 文件中被引用。
      Visual Studio 会通过灰显告诉您此文件夹被版本控制忽略。

      【讨论】:

        【解决方案3】:

        正如已经指出的,VSCode 会自动忽略 .gitignore 中的所有内容。但是,默认情况下,它也会显式忽略某些文件夹。所有这些都可以配置。以下是您可能要采取的步骤:

        1. 查看the official documentation on Workspace settings
        2. 打开相关设置(可以选择User(全局)和Workspace)。我通常通过CTRL(或Mac 上的Command)+SHIFT+P -> > settings 来执行此操作,这将向您显示相关选择:。对于每个,您可以选择 UI 或 JSON 变体。
        3. 还要确保通过Peferences: Open Default Settings (JSON) 检查默认设置。您会发现,截至目前(2021 年 5 月),**/node_modules 也被自动排除,与其他忽略文件无关。目前默认设置如下所示:
           // Configure glob patterns for excluding files and folders in fulltext searches and quick open. Inherits all glob patterns from the `files.exclude` setting. Read more about glob patterns [here](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options).
           "search.exclude": {
               "**/node_modules": true,
               "**/bower_components": true,
               "**/*.code-search": true
           },
          
           // Controls whether to use global `.gitignore` and `.ignore` files when searching for files.
           "search.useGlobalIgnoreFiles": false,
          
           // Controls whether to use `.gitignore` and `.ignore` files when searching for files.
           "search.useIgnoreFiles": true,
          

        启用搜索node_modules

          "search.exclude": {
            "**/node_modules": false
          },
          "search.useIgnoreFiles": false
        
        • 警告:这会减慢速度很多,因为node_modules 需要永远搜索 - 至少在冷启动期间,即没有缓存的时候。 (请注意,很难估计它们的缓存是如何工作的,因为它会随着时间的推移不断发展。)
        • 为了缓解这种情况,您可能需要添加一些额外的search.exclude 设置。请注意,您必须明确列出您不想要的所有内容,因为...

        VSCode 搜索的一大缺点

        search.exclude 不支持:

        • 负前瞻/后视
        • 相互级联查询

        这样的事情行不通!

          // does NOT work! :((
          "search.exclude": {
            "**/node_modules/@types": false,
            "**/node_modules": true
          }
        

        这是一个主要问题,已经在几乎著名的issue #869 中讨论了 6 年!加入并添加到 100 多个 cmets! :)

        更新:截至 2021/8/14,该问题已从积压队列中移除并放入 On Deck 队列(但这也可能意义不大)。

        【讨论】:

          猜你喜欢
          • 2019-02-07
          • 2021-12-06
          • 2021-11-09
          • 2021-01-30
          • 2020-07-25
          • 1970-01-01
          • 2016-10-29
          • 1970-01-01
          • 2019-01-13
          相关资源
          最近更新 更多