ts-loader: ts-loader doesn't work when ts-config noEmit is set to true

TypeScript: v5.0.2 Webpack: v5.76.3

Expected Behaviour

When bundling a ESM module with noEmit, Webpack is able to generate a bundle using ts-loader

Actual Behaviour

Module build failed (from ./node_modules/ts-loader/index.js):
Error: TypeScript emitted no output for C:\Users\ms\Projects\ts-loader\index.ts.
    at makeSourceMapAndFinish (C:\Users\ms\Projects\ts-loader\node_modules\ts-loader\dist\index.js:52:18)
    at successLoader (C:\Users\ms\Projects\ts-loader\node_modules\ts-loader\dist\index.js:39:5)
    at Object.loader (C:\Users\ms\Projects\ts-loader\node_modules\ts-loader\dist\index.js:22:5)

Steps to Reproduce the Problem

  1. Clone the demo repository
  2. npm-install
  3. npm-run-build it

Location of a Minimal Repository that Demonstrates the Issue.

https://github.com/minecrawler/ts-loader

Further info

connected to #161

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 2
  • Comments: 22 (12 by maintainers)

Most upvoted comments

For what it’s worth, I haven’t used ts-loader with type checking on for about four years.

I think you’re right, and the root cause is I was wrong about what “level” noEmit gets ignored at in transpileModule. It turns out any setting for noEmit gets wiped out right away rather than being ignored later in the process, and so the options validation happens the same way as it does in plain tsc. We’ll need to do something to suppress the error.

It’s my understanding that ts-loader is not compatible with allowImportingTsExtensions in full checking mode, but I thought it would work in transpileOnly: true, since I believe that uses the ts.transpileModule API where noEmit would be irrelevant. I could be wrong about the details there; it’s been a long, long time since I’ve looked at ts-loader’s source. But I think transpileOnly could be made to work if it doesn’t already.

Yeah, something like that—that’s what https://github.com/TypeStrong/ts-loader#faster-builds describes via fork-ts-checker-webpack-plugin, but my sense is a lot of people are moving toward just relying on errors in-editor and in CI via a separate tsc step. It doesn’t make a ton of sense to make emit wait on type checking, in my opinion.