ts-loader fails because TypeScript produced no JavaScript for a file
Fix it fast
Most common cause, 1 of 3The tsconfig switches JavaScript output off
Turn output back on for webpack only, through the loader's compilerOptions setting, which overrides the tsconfig.
// webpack.config.js
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
compilerOptions: { noEmit: false, emitDeclarationOnly: false },
},
},
],
},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.
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.
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:
- 1The tsconfig switches JavaScript output off
--showConfig prints "noEmit": true or "emitDeclarationOnly": true, and the error ends right after the file name - 2The file sits inside node_modules
The message continues with: By default, ts-loader will not compile .ts files in node_modules. - 3A referenced project does not compile
The 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.
grep -n -E "noEmit|emitDeclarationOnly|allowImportingTsExtensions" tsconfig*.jsonFix
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.
// 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.
npx webpack --mode developmentConfirmed by typescriptlang.org
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.
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.
// 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.
npx webpack --mode developmentConfirmed by raw.githubusercontent.com
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.
grep -n "projectReferences" webpack.config.js
npx tsc --buildFix
Read and fix the errors that tsc --build prints for the referenced project, then run webpack again.
npx tsc --build
npx webpackVerify
tsc --build finishes with no errors, and the webpack output no longer carries the referenced-projects hint.
npx tsc --build && npx webpack --mode developmentConfirmed by raw.githubusercontent.com
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.