【问题标题】:TypeScript error "Could not find a declaration file for module" - unable to fixTypeScript 错误“找不到模块的声明文件” - 无法修复
【发布时间】:2019-01-18 23:37:54
【问题描述】:

我通常能够轻松解决此错误,但这次似乎没有任何效果。

我的main.ts 文件有这个:

import locale from 'element-ui/lib/locale/lang/en';

错误:

ERROR in /Volumes/SuperData/Sites/reelcrafter/rc-ts/src/main.ts
6:20 Could not find a declaration file for module 'element-ui/lib/locale/lang/en'. '/Volumes/SuperData/Sites/reelcrafter/rc-ts/node_modules/element-ui/lib/locale/lang/en.js' implicitly has an 'any' type.
  Try `npm install @types/element-ui` if it exists or add a new declaration (.d.ts) file containing `declare module 'element-ui';`
    4 | import store from './store';
    5 | import ElementUI from 'element-ui';
  > 6 | import locale from 'element-ui/lib/locale/lang/en';
      |                    ^
    7 | import VueDragDrop from 'vue-drag-drop';
    8 | import './styles/element-setup.scss';
    9 | import './bootstrap/amplify-setup';
No lint errors found
Version: typescript 3.0.1, tslint 5.11.0

在根级别的declarations.d.ts 中,我添加了以下内容:

declare module 'element-ui';

这并不能解决问题。 declare module 'element-ui/*'; 也没有。我该如何解决?

复制回购:https://github.com/ffxsam/repro-element-ts-bug

【问题讨论】:

  • 你检查过你的 tsconfig.json 文件吗?
  • declare module 'element-ui/*'; 为我工作。您是否使用了普通 tsc 以外的构建工具?
  • @Abhishek 检查了什么?你能说得更具体点吗?
  • @MattMcCutchen 我在一个由 vue-cli 3.0 搭建的 Vue 项目中。
  • 我在 npmjs.com/package/vue-cli 上看不到 vue-cli 3.0。我只是想尝试创建一个新项目,看看是否可以重现该问题。如果您这样做可能会更容易,如果您遇到问题,请发布存储库以便我查看。

标签: javascript typescript element-ui


【解决方案1】:

创建一个名为shims-element-ui.d.ts 的声明文件,其内容如下:

declare module 'element-ui/*';

【讨论】:

    猜你喜欢
    • 2020-08-02
    • 2019-12-29
    • 2013-08-21
    • 2019-10-14
    • 2017-08-13
    • 1970-01-01
    • 1970-01-01
    • 2019-03-06
    • 2021-04-17
    相关资源
    最近更新 更多