美文网首页
vue3+typscript项目中不能 import ".ts

vue3+typscript项目中不能 import ".ts

作者: 东方三篇 | 来源:发表于2021-09-02 10:36 被阅读0次

error TS2691: An import path cannot end with a '.ts' extension. Consider importing '@/types/index.js' instead. import { myAMap } from '@/types/index.ts'

这个是由于使用了 别名 alias 导致的。

以 tsconfig.json 的拓展形式兼容配置

# 在tsconfig.json 文件中加入这一句
"extends": "./tsconfig.extends.json"

按照目录 创建 tsconfig.extends.json 文件

# tsconfig.extends.json 输入一下内容
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    }
  }
}

报错如图

extends.png
alias error.png

相关文章

网友评论

      本文标题:vue3+typscript项目中不能 import ".ts

      本文链接:https://www.haomeiwen.com/subject/vvmqwltx.html