I recently added the antlr4ng
(version 3.0.4) package to my package.json
in my TypeScript project (Node.js version 20.11.1). It works as expected except if it is used within a Jest test, in which case I get this error at runtime:
SyntaxError: /Users/XXX/node_modules/.pnpm/antlr4ng@3.0.4_antlr4ng-cli@2.0.0/node_modules/antlr4ng/dist/index.cjs: Static class blocks are not enabled. Please add `@babel/plugin-transform-class-static-block` to your configuration.
As suggested by the error message, I added the package @babel/plugin-transform-class-static-block
(version 7.24.4) to the Babel test plugins, but this did not resolve the error.
This is caused by a combination of using react-app-rewired
instead of jest
directly and using transformIgnorePatterns
. This issue is documented here and here.