简体   繁体   English

TypeScript 错误“找不到模块的声明文件”-无法修复

[英]TypeScript error "Could not find a declaration file for module" - unable to fix

I'm normally able to resolve this error easily enough, but this time nothing seems to work.我通常能够很容易地解决这个错误,但这次似乎没有任何效果。

My main.ts file has this:我的main.ts文件有这个:

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

The error:错误:

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

In my declarations.d.ts at root level, I added the following:在根级别的declarations.d.ts .d.ts 中,我添加了以下内容:

declare module 'element-ui';

This doesn't fix it.这不能解决它。 Nor does declare module 'element-ui/*';也不declare module 'element-ui/*'; . . How do I fix it?我如何解决它?

Reproduction repo: https://github.com/ffxsam/repro-element-ts-bug复现仓库: https : //github.com/ffxsam/repro-element-ts-bug

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

 declare module 'element-ui/*';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在反应中找不到模块错误的声明文件 - Could not find a declaration file for module error in react 打字稿:找不到模块“react-cards”的声明文件 - Typescript: Could not find a declaration file for module 'react-cards' 找不到模块的声明文件 - Could not find a declaration file for module 错误:“无法找到模块'react-search-input'的声明文件” - Error: “Could not find a declaration file for module 'react-search-input'” 错误:找不到模块 VueJS 应用程序的声明文件 - Error: Could not find declaration file for module VueJS application 无法找到模块'drivelist'的声明文件 - Could not find a declaration file for module 'drivelist' 找不到模块“mymodule”的声明文件 - Could not find a declaration file for module 'mymodule' 找不到模块“react”的声明文件 - Could not find a declaration file for module 'react' 在 TypeScript 中使用 SweetAlert2,找不到模块“sweetalert2/dist/sweetalert2.js”的声明文件 - Using SweetAlert2 with TypeScript, could not find a declaration file for module 'sweetalert2/dist/sweetalert2.js' Cloudinary-React 找不到模块“cloudinary-react”的声明文件 - 不使用 TypeScript - Cloudinary-React Could not find a declaration file for module 'cloudinary-react' - Not using TypeScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM