Source maps are always being configured as inline when using a .swcrc file. This causes incorrect line numbers to be reported in stack traces because source-map-support requires the hookRequire option to be set to true to process inline source maps, however @swc-node/sourcemap-support does not set this option and there is no way to configure it to do so.
Reproduction
tsconfig.json
{
"compilerOptions": {
"module": "CommonJS",
"sourceMap": true
}
}
.swcrc
{
"jsc": {
"parser": {
"syntax": "typescript",
},
},
"sourceMaps": true,
"module": {
"type": "commonjs",
}
}
index.ts
When running node -r @swc-node/register ./index.ts, the line number (1) in the first line of error's stack trace is correct:
$ node -r @swc-node/register ./index.ts
/swc-node/test/index.ts:2
throw new Error();
^
Error:
at Object.<anonymous> (/swc-node/test/index.ts:1:7)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Module._compile (/swc-node/node_modules/.pnpm/[email protected]/node_modules/pirates/lib/index.js:136:24)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Object.newLoader [as .ts] (/swc-node/node_modules/.pnpm/[email protected]/node_modules/pirates/lib/index.js:141:7)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Function.Module._load (node:internal/modules/cjs/loader:938:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47
Node.js v20.9.0
However, when using the .swcrc file with SWCRC=true node -r @swc-node/register ./index.ts, the line number (2) in the first line of the stack trace is incorrect:
$ SWCRC=true node -r @swc-node/register ./index.ts
/swc-node/test/index.ts:2
throw new Error();
^
Error:
at Object.<anonymous> (/swc-node/test/index.ts:2:7)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Module._compile (/swc-node/node_modules/.pnpm/[email protected]/node_modules/pirates/lib/index.js:136:24)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Object.newLoader [as .ts] (/swc-node/node_modules/.pnpm/[email protected]/node_modules/pirates/lib/index.js:141:7)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Function.Module._load (node:internal/modules/cjs/loader:938:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47
Node.js v20.9.0
Although the sourceMaps config option can take the values true | "inline" | false, the value in the .swcrc file is ignored and it is always being being set as "inline" in the options passed to SWC. This causes sourcemaps to not be handled correctly by source-map-support, since inline sourcemaps support requires setting the hookRequire option.
Source maps are always being configured as inline when using a
.swcrcfile. This causes incorrect line numbers to be reported in stack traces becausesource-map-supportrequires thehookRequireoption to be set to true to process inline source maps, however@swc-node/sourcemap-supportdoes not set this option and there is no way to configure it to do so.Reproduction
tsconfig.json
.swcrc
index.ts
When running
node -r @swc-node/register ./index.ts, the line number (1) in the first line of error's stack trace is correct:However, when using the
.swcrcfile withSWCRC=true node -r @swc-node/register ./index.ts, the line number (2) in the first line of the stack trace is incorrect:Although the
sourceMapsconfig option can take the valuestrue | "inline" | false, the value in the.swcrcfile is ignored and it is always being being set as "inline" in the options passed to SWC. This causes sourcemaps to not be handled correctly bysource-map-support, since inline sourcemaps support requires setting the hookRequire option.