Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

When I try to compile a .ts file I get the following error:

Module build failed: Error: Typescript emitted no output for C:\xampp\htdocs\node-api\src\js\server.ts. 
at successLoader (C:\xampp\htdocs\node-api\node_modules\ts-loader\dist\index.js:39:15)
at Object.loader (C:\xampp\htdocs\node-api\node_modules\ts-loader\dist\index.js:21:12)

For compiling I use the following config files.

Webpack:

const path = require( 'path' ),
    CleanWebpackPlugin = require( 'clean-webpack-plugin' );
module.exports = env => {
    return {
        mode: env.dev ? 'development' : 'production',
        entry: {
            'server': './src/js/server.ts'
        output: {
            path: __dirname,
            filename: './dist/js/[name].js',
        externals: '/node_modules',
        module: {
            rules: [
                    test: /\.js$/,
                    exclude: ['/node_modules/', '/src/scss/'],
                    use: [
                        'babel-loader'
                    test: /\.ts(x?)$/,
                    exclude: ['/node_modules/', '/src/scss/'],
                    use: [
                        'babel-loader',
                        'ts-loader',
                    test:  /\.json$/,
                    loader: 'json-loader'
        resolve: {
            extensions: ['.ts', '.tsx', '.js' ],
            alias: {
                '@': path.resolve(__dirname, './src/js')
        plugins: [
            new CleanWebpackPlugin(['./dist/js', './dist/css']),

Typescript:

"compilerOptions": { "removeComments": true, "preserveConstEnums": true, "allowJs": true, "outDir": "./dist/js", "target": "es5", "moduleResolution": "node", "module": "es2015", "lib": [ "es2015", "es2016" "exclude": [ "node_modules"

Babel:

"presets": [ "env", { "targets": { "node": "current" "stage-2", "es2015" "plugins": ["dynamic-import-node"]

As suggested in some other questions I've already changed the order of resolve extensions but that didn't solve it (.js before .ts) . Typescript 2.8.3 is used in combination with Node 8.11.1 and Mongoose 5.0.15 and compiled by Webpack 4.6. So I'm still wondering how to to solve the error mentioned above.

Please set noEmit to false in your tsconfig.json. By default it sets to true, once we change it to false we may not get this error.

"noEmit": false

I like this option, since it allows noEmit: true in tsconfig, which prevents output except during build. @BEvo it is available, but you may need to change use: 'ts-loader' to loader: 'ts-loader'. – Joakim Apr 17, 2022 at 12:35

Using webpack 5 and Typescript 4.5, I can run an expressjs + prisma server with the following:

webpack.config.js:

const path = require('path');
module.exports = {
  entry: './src/index.ts',
  module: {
    rules: [
        test: /\.tsx?$/,
        use: [
            loader: 'ts-loader',
            options: {
              compilerOptions: {noEmit: false},
        exclude: /node_modules/,
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),

tsconfig.json:

"compilerOptions": { "skipLibCheck": true, "strict": true, "forceConsistentCasingInFileNames": true, "noEmit": true, "esModuleInterop": true, "module": "CommonJS", "moduleResolution": "node", "resolveJsonModule": true, "jsx": "preserve", "incremental": true "include": [ "**/*.ts" "exclude": [ "node_modules"

Source: https://webpack.js.org/guides/typescript/

In my case I had to remove "emitDeclarationOnly": true from the tsconfig.json

(or just set it to false)

With this on, it will only output d.ts files and not JavaScript files.

Read more: https://www.typescriptlang.org/tsconfig#emitDeclarationOnly

Exactly! That is the correct answer. Using webpack 5.76 and ts-loader 9.4 here. Thank you. – danb4r Mar 17 at 21:35

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.