Typescript + webpack: typescript did not produce output for index.d.ts

I followed this tutorial to install typescript + webpack (no response) with success. Everything works fine until I add the index.d.ts file to my components folder, which I use to export all my modules, for example:

export * from "./MyClass1"; export * from "./MyClass2"; export * from "./MyClass2"; 

Then I import it:

 import * as MyLib from "./components"; 

Code summary and everything works fine in a sublime editor.

Initially, when I run it, I have:

Cannot resolve "file" or "directory". / components

So, I added d.ts to the extensions in webpack.config.js:

  resolve: { extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js", ".d.ts"] }, 

Now when I start webpack, I get this error:

Typescript does not output for [...] \ index.d.ts

How do I solve this problem?

+2
source share
2 answers

index.d.ts

This is a declaration file. There is no javascript emit in the declaration file.

Fix

instead of adding .d.ts as a resolvable extension (don't do this!), add .d.ts to the compilation context using something like tsconfig.json

More details

https://alm-tools.gitbooks.io/alm/content/config/tsconfig.html

+1
source

In this particular question, the contents of index.d.ts were not a definition, but a module, and it was followed by the index.ts file index.ts . I also ran into the error "typescript is not displayed for index.d.ts", but with valid creatives.

It seems that ts-loader trying to add the .d.ts files to the final bundle, but does not find anything to add, since they contain only declarations necessary for type checking at build time.

The working solution for me is not transferring the .d.ts files to ts-loader but to some kind of bootloader that does nothing, like ignore-loader . Relevant rules in my webpack.config.js :

 { test: /\.tsx?$/, loader: 'ts-loader', exclude: /node_modules|\.d\.ts$/ }, { test: /\.d\.ts$/, loader: 'ignore-loader' }, 

ts-loader can be configured a little differently if you use ES2018, where a negative look behind regular expressions has been added:

 { test: /(?<!\.d)\.tsx?$/, loader: 'ts-loader', exclude: /node_modules/ }, //same ignore-loader config here 
+2
source

All Articles