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

AWS Cloud9 TypeScript报错VS Code无此问题,原因及修复方案咨询

问题原因

AWS Cloud9内置的TypeScript语言服务版本通常滞后于最新版VS Code。VS Code默认会适配项目本地安装的TypeScript版本或同步更新语言服务,对NextJS 14新增的Metadata类型支持完善;而Cloud9可能仍在使用旧版全局TypeScript,或未自动切换到项目本地的TS版本,导致无法正确解析NextJS的新类型定义。

修复方案
  • 强制使用项目本地TypeScript版本

    1. 点击Cloud9右上角齿轮图标打开设置面板
    2. 导航到Editor > Language > TypeScript
    3. 将TypeScript版本选项切换为Workspace,让编辑器使用项目node_modules内的typescript@5.3.3版本
  • 更新全局TypeScript版本(若Workspace选项无效)
    执行以下命令替换全局旧版TS:

    npm uninstall -g typescript
    npm install -g typescript@5.3.3
    

    完成后重启Cloud9编辑器生效

  • 验证tsconfig.json配置
    确保配置文件包含NextJS类型支持的必要项:

    {
      "compilerOptions": {
        "target": "ES2022",
        "module": "ESNext",
        "lib": ["ES2022", "DOM", "DOM.Iterable"],
        "jsx": "preserve",
        "moduleResolution": "bundler",
        "strict": true,
        "noEmit": true,
        "plugins": [{ "name": "next" }]
      },
      "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
      "exclude": ["node_modules"]
    }
    

    重点确认include数组包含.next/types/**/*.ts,这是NextJS自动生成的Metadata类型文件存放路径

  • 重启TypeScript服务并清理缓存

    1. 按下Ctrl+Shift+P打开Cloud9命令面板
    2. 输入并执行TypeScript: Restart TS Server
    3. 删除项目根目录的.next文件夹,运行npm run dev重新生成类型文件

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 18:40:03