Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

antlr4ts uses a Node module that is incompatible with browsers. #551

Open
Logopher opened this issue Dec 2, 2024 · 2 comments
Open

antlr4ts uses a Node module that is incompatible with browsers. #551

Logopher opened this issue Dec 2, 2024 · 2 comments

Comments

@Logopher
Copy link

Logopher commented Dec 2, 2024

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.

Cc @unsupervisednn

@mschienbein
Copy link

I have this exact same issue, and the same stack even.

@dgadelha
Copy link

dgadelha commented Jan 4, 2025

Check out antlr4ng

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants