TypeStrong / ts-loader

TypeScript loader for webpack
https://johnnyreilly.com/ts-loader-goes-webpack-5
MIT License
3.44k stars 429 forks source link

Error when upgrading ts-loader #1638

Closed michaeltford closed 7 months ago

michaeltford commented 7 months ago

I now get a null pointer exception

mappings: inputSourceMap.mappings,

This is because my prod build is not generating source maps and somehow the inputSourceMap is null (I am not setting it). The following code checks for undefined but not null.

If I change the following

https://github.com/TypeStrong/ts-loader/blob/9315855cd6f87883b137fc762da02f99a7842f46/src/index.ts#L152C3-L152C3

if (sourceMap === undefined || inputSourceMap === undefined) { callback(null, output, sourceMap); return; } to if (!sourceMap || !inputSourceMap) { callback(null, output, sourceMap); return; } everything works as expected.

johnnyreilly commented 7 months ago

What are the false-y values being passed that are triggering this? '' ? null? Also what is the nature of your upgrade?

michaeltford commented 7 months ago

John

thank you for the very quick response.

falsey value is null. I did yarn upgrade ts-loader (from version 8.x? to 9.5.0).

TLDR

Sorry for the obtuse problem statement. I don't fully understand. I have a repo (I will publish the source in the next few weeks) that uses the create react template to generate a typescript project (so most of the code is a blackbox to me.) I did a yarn upgrade to ts-loader (and a few other packages) and I started getting an error. After several hours I figured out that ts-loader was throwing a null pointer exception because somehow the inputSourceMap is null (I honestly don't know where it's coming from but I suspect it's either from babel-loader or perhaps I have a tsconfig setting that is invalid?). This only happens with the ts-loader > 8.

{ test: /\.(ts|tsx|jsx|ts)$/, use: ["babel-loader", "ts-loader"], exclude: /node_modules/, },

The 'simple' solution (and maybe correct?) seemed to be to allow for the inputs to be falsy and not just check undefined.

johnnyreilly commented 7 months ago

Sure, but are you able to confirm the nature of the false-y values that triggers this? '' ? null?

It's the first time this has been reported. Also are you chaining loaders?

michaeltford commented 7 months ago

The inputSourceMap value is null. I am not sure who is setting it. (I assume it's the babel loader as I am not deliberately) Yes, but the only loader before ts-loader is babel-loader (see in comments above.

It is possible there is an issue in my config but I don't know where it could be.

My question is should false-y values (or at least null) be supported as a valid inputtype? I would think so since you support undefined.

johnnyreilly commented 7 months ago

Okay so I'm pretty sure the last release introduced the issue: https://github.com/TypeStrong/ts-loader/pull/1626

I think inputSourceMap should have a false-y check

michaeltford commented 7 months ago

Thanks John

johnnyreilly commented 7 months ago

no worries - thanks for helping diagnose an issue!

johnnyreilly commented 7 months ago

Fix should be released with https://github.com/TypeStrong/ts-loader/releases/tag/v9.5.1