Skip to content

Instantly share code, notes, and snippets.

@caprica
Created December 2, 2024 09:52
Show Gist options
  • Save caprica/7f322e25b9fa6898c91582ca68b733a4 to your computer and use it in GitHub Desktop.
Save caprica/7f322e25b9fa6898c91582ca68b733a4 to your computer and use it in GitHub Desktop.
Tweak tsconfig.json if needed to enable newer features in Node (custom Error constructor)

When using nx to generate a Javascript library, the tsconfig it generates does not allow to use newer language/platform versions, for examle the Error constructor:

export class SomeCustomError extends Error {
    constructor(message: string, err?: Error) {
        super(message, { cause: err })           // <--- it will complain about 'cause' here
        this.name = this.constructor.name
    }
}

To resolve, tweak the tsconfig.json in the library project directory:

{
  "target": "esnext",
  "module": "commonjs",
  "lib": ["esnext"],
}

It has "module": "commonjs" by default.

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