Skip to content

Node 20: errors produced by reportTSError are not serialised correctly when using ESM loader #2026

@danrr

Description

@danrr

Search Terms

Node 20, reportTSError, error

Expected Behavior

When using the ts-node/esm loader with Node 18, TS errors are reported correctly. The file below when run with node --experimental-loader ts-node/esm test.ts

const a = (b: 1 | 2) => b + 1

console.log(a(3))

produces the following correct error:

TSError: ⨯ Unable to compile TypeScript:
test.ts:3:15 - error TS2345: Argument of type '3' is not assignable to parameter of type '1 | 2'.

3 console.log(a(3))
<stack trace>
  diagnosticCodes: [ 2345 ]

Actual Behavior

On Node 20, the error is serialised to only retain diagnosticCodes and no other info

node:internal/process/esm_loader:42
      internalBinding('errors').triggerUncaughtException(
                                ^
{ diagnosticCodes: [ 2345 ] }

Likely related to https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V20.md#custom-esm-loader-hooks-run-on-dedicated-thread

Steps to reproduce the problem

Run command above on Node 20

Minimal reproduction

TypeStrong/ts-node-repros#33

https://github.com/TypeStrong/ts-node-repros/actions/runs/5057165129/jobs/9075579140

Specifications

  • ts-node v10.9.1
  • node v18.16.0
  • TS compiler v5.0.4

and

  • ts-node v10.9.1

  • node v20.2.0

  • TS compiler v5.0.4

  • package.json:

{
  "type": "module",
}
  • Operating system and version: MacOS 13.4
  • If Windows, are you using WSL or WSL2?:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions