element-plus打包时报错Cannot find type definition file for 'element-plus/global'.

1,477 阅读1分钟

报错内容:

Cannot find type definition file for 'element-plus/global'. The file is in the program because: Entry point of type library 'element-plus/global' specified in compilerOptions

解决办法:

  • 在tsconfig.json中配置
{
    "compilerOptions": {
        //...
        "types": ["element-plus/global.d.ts"]
    }
}

element-plus按需要导入,ts无法提示,如果按照 "types": ["element-plus/global.d.ts"]没用处

解决办法:

当配置了按需引入(详细见官网),但ts无法提示,运行 npm run dev后会在根目录生成两个文件:

auto-imports.d.ts
components.d.ts

tsconfig.jsontsconfig.app.json配置

{
    "include":["auto-imports.d.ts","components.d.ts"]
}