90

I've got this configuration from https://www.npmjs.com/package/ts-loader:

webpack.config.js:

var path = require('path');
var webpack = require('webpack');

module.exports = {
    mode: "development",
    devtool: "inline-source-map",
    entry: "./src/Api.ts",
    output: {
        filename: "bundle.js"
    },
    resolve: {
        // Add `.ts` and `.tsx` as a resolvable extension.
        extensions: [".ts", ".tsx", ".js"]
    },
    module: {
        rules: [
            // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
            { test: /\.tsx?$/, loader: "ts-loader" }
        ]
    }
};

./src/Api.ts:

export class Api {
...
}

But when I run webpack I get:

Error: TypeScript emitted no output for Api.ts
Claudiu Creanga
  • 8,031
  • 10
  • 71
  • 110
  • (Just a shot in the dark) Do you by chance have any outdated compiled javascript in the same directory as your ts? I had an issue similar to this which ended up being cause by some out of date compiled files. – Code2Code Mar 22 '19 at 17:06
  • @Code2Code no, cleaned everything up. Is there enough to have `export class Api { ... }` or do I need to instantiate it in that file too? – Claudiu Creanga Mar 22 '19 at 17:11
  • It is enough to export, since TS is a static type checker. – felixmosh Mar 22 '19 at 17:12

2 Answers2

270

Check that you don't have noEmit set to true In your tsconfig.json file.

felixmosh
  • 32,615
  • 9
  • 69
  • 88
8

First change webpack config entry like index.js to index.tsx. Second make sure rule added for tsx file like:

{
  test: /\.(ts|js)x?$/,
  exclude: /node_modules/,
  use: {
    loader: "babel-loader",
    options: {
      presets: [
        "@babel/preset-env",
        "@babel/preset-react",
        "@babel/preset-typescript",
      ],
    },
  },
},
Josef
  • 2,869
  • 2
  • 22
  • 23
Soshiv Upreti
  • 101
  • 1
  • 6