Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.swcrc config file sourceMaps option is ignored and always set to "inline", causing incorrect stack traces when using a .swcrc file #741

Closed
dsyddall opened this issue Nov 12, 2023 · 0 comments · Fixed by #742

Comments

@dsyddall
Copy link
Contributor

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

throw new Error();

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/pirates@4.0.5/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/pirates@4.0.5/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/pirates@4.0.5/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/pirates@4.0.5/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant