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

Visual Studio 2022:Angular升级后无法找到TS模块

解决Angular 17升级后Visual Studio 2022 IntelliSense「Cannot find module」错误
  • 同步TypeScript版本
    Angular 17要求TypeScript 5.2及以上版本,VS2022默认的TS版本可能不匹配。打开「工具」>「选项」>「文本编辑器」>「JavaScript/TypeScript」>「语言服务」,将「TypeScript版本」设置为「使用工作区版本(node_modules/typescript)」,确保和项目依赖的TS版本一致。

  • 清理IntelliSense缓存
    关闭所有VS窗口,删除以下目录的缓存文件:

    • %LOCALAPPDATA%\Microsoft\VisualStudio\<你的VS版本号>\ComponentModelCache
    • %USERPROFILE%\AppData\Local\Temp\VSJavaScriptServices
      重新打开项目,让IntelliSense重新生成缓存。
  • 完善tsconfig.json配置
    原配置缺少Angular项目必备的编译选项,补充后可修复模块解析问题。修改后的配置参考:

    {
        "compileOnSave": false,
        "compilerOptions": {
            "allowSyntheticDefaultImports": true,
            "baseUrl": "./",
            "declaration": false,
            "experimentalDecorators": true,
            "lib": [
                "es2020",
                "dom"
            ],
            "module": "es2020",
            "moduleResolution": "node",
            "outDir": "./dist/out-tsc",
            "resolveJsonModule": true,
            "sourceMap": true,
            "target": "es2020",
            "typeRoots": [
                "node_modules/@types"
            ],
            "esModuleInterop": true,
            "skipLibCheck": true
        },
        "angularCompilerOptions": {
            "enableI18nLegacyMessageIdFormat": false,
            "strictInjectionParameters": true,
            "strictInputAccessModifiers": true,
            "strictTemplates": true
        }
    }
    

    其中esModuleInterop解决ES模块导入兼容问题,skipLibCheck跳过第三方库的类型检查以减少报错,angularCompilerOptions是Angular项目必须的编译器配置。

  • 更新项目TypeScript依赖
    检查package.json的devDependencies中typescript版本是否为~5.2.0或更高,若不是,运行命令:

    npm install typescript@~5.2.0 --save-dev
    
  • 重新加载项目
    右键项目选择「重新加载项目」,或关闭VS后重新打开,确保IntelliSense重新读取所有配置和依赖。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 13:23:28