antlr4ts uses a Node module that is incompatible with browsers.Β #551
Description
I'm trying to use antlr4ts in the browser. This previously worked in a more traditional React project, but I've been migrating to a Visual Studio solution using the same Vite + React + TS stack. When I launch that solution, I get an error:
BitSet.ts:834 Uncaught TypeError: Cannot read properties of undefined (reading 'custom')
at node_modules/antlr4ts/misc/BitSet.js (BitSet.ts:834:32)
at node_modules/antlr4ts/atn/ATNConfigSet.js (ATNConfigSet.ts:15:1)
at node_modules/antlr4ts/dfa/DFA.js (DFA.ts:10:1)
at node_modules/antlr4ts/atn/ATN.js (ATN.ts:12:1)
at node_modules/antlr4ts/atn/LexerATNSimulator.js (LexerATNSimulator.ts:10:1)
A warning above the error says:
browser-external:util:9 Module "util" has been externalized for browser compatibility. Cannot access "util.inspect" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
BitSet.ts declares a method:
public [(util.inspect as any).custom](): string {
return "BitSet " + this.toString();
}
This problem also affects https://www.npmjs.com/package/antlr4ts-browser built from the pull request here: #440
I've tested in Firefox and Edge with the same results.