I recently developed a npm package using TSdx to create a small Jest reporter. However, when I try to use this package in another project, an error occurs.
Uncaught TypeError: Class constructor BaseReporter cannot be invoked without 'new'
at new ExampleReporter (..\dist\example-reporter.cjs.development.js:37:26)
The ExampleReporter
extends from the BaseReporter
class provided by Jest.
import BaseReporter from '@jest/reporters/build/base_reporter';
export class ExampleReporter extends BaseReporter {
// ...
}
Referring to Class constructor cannot be invoked without 'new', it appears that setting up Babel could resolve the issue. Unfortunately, there is no clear solution for this within the TSdx documentation.
How should I configure the TSdx build
to address this problem?
You can replicate this error by enabling watch mode.
$ npx tsdx watch --onSuccess node .
...
Watching for changes
Welcome to Node.js v12.18.2.
Type ".help" for more information.
> new (require('.').ExampleReporter)()
Uncaught TypeError: Class constructor BaseReporter cannot be invoked without 'new'