You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode IntelliSense自动补全对Node模块及本地文件失效问题求助

解决VSCode JS项目IntelliSense补全失效问题

第三方库(steam-user、discord.js)补全修复

  • 安装对应库的类型声明文件:
    针对steam-user执行:npm install @types/steam-user --save-dev
    针对discord.js执行:npm install @types/discord.js --save-dev
  • 切换TypeScript版本为工作区版本:
    打开VSCode设置(快捷键Ctrl+,),搜索typescript.tsdk,选择使用项目本地安装的TypeScript版本,而非VSCode内置版本。
  • 重启TypeScript服务:
    打开命令面板(Ctrl+Shift+P),执行TypeScript: Restart TS Server命令。

本地JSON文件(config.json)补全修复

  • 用JSDoc注释增强类型提示:
    在引用config的JS文件中添加注释:
    /** @type {{ accountName: string; password: string }} */
    const config = require("./config.json");
    
  • 关联JSON Schema:
    在config.json顶部添加schema关联注释,同时创建对应schema文件:
    /* { "$schema": "./config-schema.json" } */
    {
      "accountName": "something",
      "password": "something2"
    }
    
    创建config-schema.json:
    {
      "type": "object",
      "properties": {
        "accountName": { "type": "string" },
        "password": { "type": "string" }
      },
      "required": ["accountName", "password"]
    }
    

通用排查步骤

  • 项目根目录创建jsconfig.json:
    {
      "compilerOptions": {
        "module": "CommonJS",
        "target": "ES6",
        "checkJs": true
      },
      "include": ["**/*.js", "**/*.json"]
    }
    
  • 完全关闭VSCode后重新打开项目文件夹,确保依赖被正确加载。

内容的提问来源于stack exchange,提问作者berriz44

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 21:32:44