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.