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
- Clone the demo repository
- npm-install
- 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)
For what it’s worth, I haven’t used ts-loader with type checking on for about four years.
Looks like it’s working in Cypress: https://github.com/cypress-io/cypress/issues/26148#issuecomment-1493467682
I think you’re right, and the root cause is I was wrong about what “level”
noEmitgets ignored at intranspileModule. It turns out any setting fornoEmitgets 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 plaintsc. We’ll need to do something to suppress the error.It’s my understanding that ts-loader is not compatible with
allowImportingTsExtensionsin full checking mode, but I thought it would work intranspileOnly: true, since I believe that uses thets.transpileModuleAPI wherenoEmitwould 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 thinktranspileOnlycould 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 separatetscstep. It doesn’t make a ton of sense to make emit wait on type checking, in my opinion.