antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.11k stars 3.28k forks source link

Typescript tsconfig.json error in node package. #4280

Closed sudosu98 closed 1 year ago

sudosu98 commented 1 year ago

When i use the antlr4 npm package the tsconfig.json throws an error Cannot find type definition file for 'node'. Although I have included @types/node and @types/antlr4. I am using antlr4 v4.13.0.

Screenshot from 2023-05-23 10-51-30

kaby76 commented 1 year ago

The way I do this is with a stripped-down tsconfig.json (see tsconfig.json from the grammars-v4 build), and a package.json with the package references (see package.json from the grammars-v4 build).

The instructions for the Typescript target could be improved. Not to single out Typescript, all the target docs are missing an essential part that describes the build environment around the source code. I am no expert on TS, and ChatGPT answers don't usually work. It took me months to devise build solutions for 8 antlr targets for grammars-v4.

The build json files should be part of the documentation for the Typescript target because the build environment is at least as important--if not more so--than the driver source code. A "script" needs to be added to call the Antlr tool using antlr4. And, it should be robust enough to handle Github Dependabot PRs that only work on the Antlr runtime target, since Dependabot does not understand how to upgrade the version used for the Antlr tool.

sudosu98 commented 1 year ago

I noticed that my tsconfig was using 'commonjs' and antlr uses 'ESM' . I changed the module type for my project and it stopped throwing this error or maybe i also added the moduleResolution as 'Node'. It has stopped emitting that error for now.

kaby76 commented 1 year ago

I noticed that my tsconfig was using 'commonjs' and antlr uses 'ESM' . I changed the module type for my project and it stopped throwing this error or maybe i also added the moduleResolution as 'Node'. It has stopped emitting that error for now.

Proof (again) that the build environment is at least as important--if not more so--than the driver source code.

ericvergnaud commented 1 year ago

You should not be using @types/antlr4. ANTLR4 now directly supports typescript.Envoyé de mon iPhoneLe 25 mai 2023 à 12:55, Ken Domino @.***> a écrit :

I noticed that my tsconfig was using 'commonjs' and antlr uses 'ESM' . I changed the module type for my project and it stopped throwing this error or maybe i also added the moduleResolution as 'Node'. It has stopped emitting that error for now.

Proof (again) that the build environment is at least as important--if not more so--than the driver source code.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>