当“node_modules”存在时,VScode 智能感知非常慢

问题描述 投票:0回答:4

VScode intelliSense 在处理某些 TypeScript、NextJs 项目时太慢。 问题似乎是

node_modules
文件夹,当我删除
node_modules
时,intelliSense 似乎运行得非常快。我已经尝试了 StackOverflow 的许多解决方案,但似乎都不起作用。

我试过了:

  • 禁用所有扩展
  • 切换到 VScode insiders 版本。
  • target
     中的 
    es6
     属性更改为 
    tsconfig.json

但问题仍然存在。

我的

tsconfig.json
看起来像这样:

{
    "compilerOptions": {
        "target": "es5",
        "lib": ["dom", "dom.iterable", "esnext"],
        "allowJs": true,
        "skipLibCheck": true,
        "strict": true,
        "forceConsistentCasingInFileNames": true,
        "noEmit": true,
        "esModuleInterop": true,
        "module": "esnext",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "jsx": "preserve",
        "baseUrl": "./",
        "paths": {
            "@components/*": ["./components/*"],
            "@containers/*": ["./containers/*"],
            "@assets/*": ["./assets/*"],
            "@icons/*": ["./assets/Icons/*"],
            "@logo": ["./assets/Logo/MemeChat"],
            "@styles/*": ["./styles/*"],
            "@ui/*": ["./components/UI/*"],
            "@aws/*": ["./aws/*"],
            "@store/*": ["./store/*"],
            "@hooks/*": ["./hooks/*"],
            "@reducer/*": ["./reducer/*"],
            "@types": ["./types/types.ts"],
            "@constants": ["./constants/CONSTANTS.ts"]
        },
        "incremental": true
    },
    "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
    "exclude": ["node_modules", ".next", "node_modules/**", "node_modules/*"]
}

我的

package.json
看起来像这样:

{
    "name": "meme-chat",
    "version": "0.1.0",
    "private": true,
    "scripts": {
        "dev": "next dev",
        "build": "next build",
        "start": "next start",
        "lint": "next lint",
        "host": "next dev -H 192.168.1.7"
    },
    "dependencies": {
        "amazon-cognito-identity-js": "^5.1.0",
        "next": "^12.1.6",
        "react": "^18.2.0",
        "react-dom": "^18.2.0",
        "styled-components": "^5.3.5"
    },
    "devDependencies": {
        "@types/node": "^18.0.0",
        "@types/react": "^17.0.33",
        "@types/react-dom": "^17.0.10",
        "@types/styled-components": "^5.1.15",
        "eslint": "7.32.0",
        "eslint-config-next": "11.1.0",
        "typescript": "^4.4.4"
    }
}
reactjs typescript visual-studio-code next.js styled-components
4个回答
1
投票

事实证明,这对我来说是一个特定的 VS Code 扩展。 角度语言服务。禁用此功能使其速度快如闪电。

试试这个看看它是否是一个特定的扩展。

打开命令面板(Ctrl+Shift+P) 输入“禁用所有已安装的扩展” 逐一或分组启用它们并测试智能感知速度


1
投票

node_modules
添加到
.gitignore
文件

我们不应该跟踪

node_modules
中的
git
,扫描其中的所有文件会减慢速度。


0
投票

就我而言,问题是完全不同的:结果是安全平台 Crowstrike Falcon。 删除它,一切又回到了惊人的速度!甚至 ngx-translate intellisense 也开始工作了。 因此,您可能还想检查您的服务中的那些服务......


0
投票

我也遇到过同样的问题,并找到了适用于我的项目的解决方案。 我最近注意到一种有趣的方法来查找导致问题的依赖关系。

请按照以下步骤操作:

  1. 首先,出于测试原因,您需要对一个文件中的所有导入进行评论。
  2. 然后使用 ctrl + shift + p 重新加载 VSCode:
    Developer: Realod Window
  3. 现在将自己置于代码中的某些语句上,您会发现 Intellisense 正在工作。
  4. 开始逐行取消注释所有导入,并在每次取消注释导入时检查 Intellisense 状态框。您会注意到哪个依赖项导致了性能问题。

就我而言,是来自

UseControllerProps
react-hook-form
类型。

在某些情况下,文件中的其他组件可能会导致此问题的性能,您会注意到导入组件时出现问题,然后您需要测试组件的文件以查找问题。

© www.soinside.com 2019 - 2024. All rights reserved.