Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

ts-loader fails because TypeScript produced no JavaScript for a file

Your error

Module build failed (from ./node_modules/ts-loader/index.js):3 more lines it can show

Fix it fast

Most common cause, 1 of 3

The tsconfig switches JavaScript output off

Turn output back on for webpack only, through the loader's compilerOptions setting, which overrides the tsconfig.

Fix
// webpack.config.js
module: {
  rules: [
    {
      test: /\.tsx?$/,
      loader: 'ts-loader',
      exclude: /node_modules/,
      options: {
        compilerOptions: { noEmit: false, emitDeclarationOnly: false },
      },
    },
  ],
},
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Module build failed with TypeScript emitted no output for a file means ts-loader asked the compiler for JavaScript and got nothing back. Usual causes: noEmit or emitDeclarationOnly in the tsconfig it reads, a .ts file under node_modules, or a referenced project with build errors. Give ts-loader a config that emits JavaScript. Applies to ts-loader 9.6 on TypeScript 5.x and 6.0.

  • Applies to ts-loader 9.6.2, TypeScript 5.x and 6.0, webpack 5.113, Node.js 22, 24 and 26
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Print the final configuration TypeScript builds from and look for the two options that switch JavaScript off, then read the end of the webpack error. ts-loader appends a hint of its own for node_modules files and for referenced projects, and no hint at all when the config is the problem. If the loader has a configFile option, pass that file to --project instead.

Run this first
npx tsc --project tsconfig.json --showConfig | grep -E '"(noEmit|emitDeclarationOnly)"'
npx webpack 2>&1 | grep -A2 "emitted no output"

Then find the line you see in this list and open its fix:

  1. 1The tsconfig switches JavaScript output off--showConfig prints "noEmit": true or "emitDeclarationOnly": true, and the error ends right after the file name
  2. 2The file sits inside node_modulesThe message continues with: By default, ts-loader will not compile .ts files in node_modules.
  3. 3A referenced project does not compileThe message continues with: The most common cause for this is having errors when building referenced projects.

What does the error look like?

  • Module build failed (from ./node_modules/ts-loader/index.js):
  • Error: TypeScript emitted no output for /app/src/index.ts.
  • TypeScript emitted no output for ... The most common cause for this is having errors when building referenced projects.
  • TypeScript emitted no output for ... By default, ts-loader will not compile .ts files in node_modules.

Cause 1 of 3

The tsconfig switches JavaScript output off

You see--showConfig prints "noEmit": true or "emitDeclarationOnly": true, and the error ends right after the file name

Check

TypeScript emitted no output for every file when the tsconfig that ts-loader loads tells the compiler not to write JavaScript. The TypeScript reference says noEmit writes no JavaScript, source maps or declarations, and emitDeclarationOnly writes only .d.ts files. ts-loader does not touch either option; it turns the empty result into this build error. Both are normal in a tsconfig meant for type checks only, where another tool such as Babel, swc or a framework bundler turns TypeScript into JavaScript, so copying such a file into a webpack project brings the problem along.

Check
grep -n -E "noEmit|emitDeclarationOnly|allowImportingTsExtensions" tsconfig*.json

Fix

Turn output back on for webpack only, through the loader's compilerOptions setting, which overrides the tsconfig. The editor and any tsc --noEmit check keep their own settings. If the same file sets allowImportingTsExtensions, switch that off too: TypeScript allows it only together with noEmit or emitDeclarationOnly.

Fix
// webpack.config.js
module: {
  rules: [
    {
      test: /\.tsx?$/,
      loader: 'ts-loader',
      exclude: /node_modules/,
      options: {
        compilerOptions: { noEmit: false, emitDeclarationOnly: false },
      },
    },
  ],
},

Verify

The build completes and the bundle contains the compiled module.

Verify
npx webpack --mode development

Confirmed by typescriptlang.org

Did this fix it?

Cause 2 of 3

The file sits inside node_modules

You seeThe message continues with: By default, ts-loader will not compile .ts files in node_modules.

Check

When the path in TypeScript emitted no output points into node_modules, a package ships raw .ts sources or a workspace package is linked there before it has been built. ts-loader skips TypeScript files under node_modules unless told otherwise, and says so in the hint it appends to the error.

Check
npx webpack 2>&1 | grep -o "emitted no output for [^ ]*node_modules[^ ]*"

Fix

First choice: build the package and import its JavaScript output. If you really must compile its sources, turn on allowTsInNodeModules and add the package to tsconfig include as well, because the option only acts as an allowlist for files the tsconfig already names.

Fix
// webpack.config.js, in the ts-loader rule
options: { allowTsInNodeModules: true },

// tsconfig.json
{
  "include": ["src", "node_modules/my-shared-lib/src"]
}

Verify

Rebuild; the node_modules hint is gone and the package code is in the bundle.

Verify
npx webpack --mode development

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

A referenced project does not compile

You seeThe message continues with: The most common cause for this is having errors when building referenced projects.

Check

With projectReferences: true in the ts-loader options, ts-loader rebuilds referenced projects the way tsc --build does and takes the JavaScript for their files from that build. When a referenced project has compile errors there is nothing to hand back, so the outer build reports no output for the file instead of the real error.

Check
grep -n "projectReferences" webpack.config.js
npx tsc --build

Fix

Read and fix the errors that tsc --build prints for the referenced project, then run webpack again.

Fix
npx tsc --build
npx webpack

Verify

tsc --build finishes with no errors, and the webpack output no longer carries the referenced-projects hint.

Verify
npx tsc --build && npx webpack --mode development

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Give webpack its own emit settings (loader compilerOptions or a separate configFile), so a later edit to the shared type-check tsconfig cannot switch JavaScript off.
  • In a repo with project references, run tsc --build in CI before webpack so the referenced project fails with its own message first.
  • Keep ts-loader projects on TypeScript 6: TypeScript 7.0 ships without the compiler API that such tools call, and its release post offers the @typescript/typescript6 package for them (npm install -D typescript@npm:@typescript/typescript6).

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, QistLock, Workforce.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.