首页 > 解决方案 > 将 typescript 升级到 4.2.x,导入路径不能以“.ts”结尾?

问题描述

当我将 typescript 从 4.1.5 升级到 4.3.2 时,我的程序无法构建。

错误信息:导入路径不能以“.ts”扩展名结尾。考虑改为导入“@/api/common.js”。

4.1.5版本还可以。4.2.x以后就不能用.ts扩展了吗?

我的 tsconfig.json:


{
  "compilerOptions": {
    "target": "es2019",
    "module": "esnext",
    "moduleResolution": "node",
    "forceConsistentCasingInFileNames": true,
    "jsx": "preserve",
    "incremental": true,
    "isolatedModules": true,
    "strict": true,
    "resolveJsonModule": true,
    "importHelpers": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "skipLibCheck": true,
    "noUnusedLocals": false,
    "types": [
      "webpack-env",
      "jest"
    ],
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "includes": ["../shared/**/**"],
  "exclude": [
    "node_modules"
  ]
}

标签: typescript

解决方案


推荐阅读