4

I have moved purely type definitions into a separate file, as index.d.ts.

However, if I run Webpack, compilation fails because \index \index.ts \index.tsx... does not exist. These correspond to my webpack config, on resolve: { extensions: [] }

If I add .d.ts to the extensions array however, the error becomes that file is not a module.

How should I configure this properly, without turning the .d.ts into a plain .ts file?

P.S. Using ts-loader

David Min
  • 1,246
  • 8
  • 27
  • is this helpful for you? https://stackoverflow.com/questions/38251505/typescript-index-d-ts-and-webpack-module-not-found-error – nima Nov 12 '21 at 12:01
  • 2
    @nima No, as the solution is either not use `.d.ts` and use plain `.ts`, or to modify the import as from `index.d` instead. VSCode when auto adding imports will use `index` instead of `index.d`, so I wouldn't want to manually write this every time - doesn't feel like that's the design way – David Min Nov 12 '21 at 12:22
  • did you find the answer? – nima Nov 17 '21 at 10:00
  • 2
    No, haven't got anything other than just use .ts for now. Will post an answer when I've looked into it properly – David Min Nov 18 '21 at 17:10
  • 1
    Any update on this? I'm facing a similar issue: in the `.d.ts` file, when I import something from other file, the `.d.ts` file works without any configuration; when no import, ts complains that the file "is not a module" – CSSer Apr 17 '22 at 02:47
  • Do you have enums in your .d.ts ? – 高欣平 Jun 09 '22 at 14:05
  • .d.ts cannot has enums – 高欣平 Jun 09 '22 at 14:06

0 Answers0