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

Warning in generated javascript code when using node 14 #2834

Closed
fvictorio opened this issue Jun 3, 2020 · 12 comments
Closed

Warning in generated javascript code when using node 14 #2834

fvictorio opened this issue Jun 3, 2020 · 12 comments
Milestone

Comments

@fvictorio
Copy link

Steps to reproduce:

  1. Install node v14.2.0

  2. Download antlr 4.8

  3. Create a basic grammar:

    grammar Grammar;
    
    main
      : ('foo' | 'bar' | 'baz')* EOF ;
    
    WS
      : [ \t\r\n\u000C]+ -> skip ;
    
  4. Generate javascript: java -jar antlr4.jar -Dlanguage=JavaScript Grammar.g4 -o src

  5. cd src && npm install antlr4

  6. Require the lexer file: node --trace-warnings -e 'require("./GrammarLexer")'

This does work, but shows a warning:

(node:20695) Warning: Accessing non-existent property 'INVALID_ALT_NUMBER' of module exports inside circular dependency
    at emitCircularRequireWarning (internal/modules/cjs/loader.js:817:11)
    at Object.get (internal/modules/cjs/loader.js:831:5)
    at Object.<anonymous> (node_modules/antlr4/RuleContext.js:30:46)
    at Module._compile (internal/modules/cjs/loader.js:1176:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
    at Module.load (internal/modules/cjs/loader.js:1040:32)
    at Function.Module._load (internal/modules/cjs/loader.js:929:14)
    at Module.require (internal/modules/cjs/loader.js:1080:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (node_modules/antlr4/PredictionContext.js:8:19)
(node:20695) Warning: Accessing non-existent property 'INVALID_ALT_NUMBER' of module exports inside circular dependency
    at emitCircularRequireWarning (internal/modules/cjs/loader.js:817:11)
    at Object.get (internal/modules/cjs/loader.js:831:5)
    at Object.<anonymous> (node_modules/antlr4/tree/Trees.js:13:49)
    at Module._compile (internal/modules/cjs/loader.js:1176:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
    at Module.load (internal/modules/cjs/loader.js:1040:32)
    at Function.Module._load (internal/modules/cjs/loader.js:929:14)
    at Module.require (internal/modules/cjs/loader.js:1080:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (node_modules/antlr4/RuleContext.js:122:13)

A similar error happens if you require RuleContext directly: node --trace-warnings -e 'require("antlr4/RuleContext")'

@manian-kumaran
Copy link

I can confirm the issue. And, it is not just only a warning, node express stops serving. So, this is critical issue.

@ericvergnaud
Copy link
Contributor

ericvergnaud commented Jun 6, 2020

I believe this is already fixed in the latest master.
No release date yet.
Surely this error can be ignored using a node express setting until the fix is released?

@palfrey
Copy link

palfrey commented Jul 28, 2020

#2749 I think is the fix for this (specifically edf24ea), which is not released yet

@ericvergnaud
Copy link
Contributor

Indeed this was fixed as part of the ES6 migration.
@parrt would suggest starting to plan a 4.9 release: Dart + ES6 + various bug fixes.... ?

@parrt
Copy link
Member

parrt commented Jul 28, 2020

Sure. Is ES6 is a big change?

@parrt parrt modified the milestone: 4.9 Jul 28, 2020
@parrt
Copy link
Member

parrt commented Jul 28, 2020

created milestone. Closing. Fixed by #2749

@parrt parrt closed this as completed Jul 28, 2020
@ericvergnaud
Copy link
Contributor

Sure. Is ES6 is a big change?

Yes, it changes the generated code, and is a major step towards an official Typescript version

@fvictorio
Copy link
Author

Hey folks, thanks for this!

I cloned the repo, built it locally from the master branch, and then used the generated JAR to re-generate my parser. But there were no changes at all. Am I missing something here?

@carocad
Copy link
Contributor

carocad commented Oct 4, 2020

I think this will be fixed with #2931 . PR #2749 only introduced a workaround to allow the runtime to compute the correct result but it didnt remove the cyclic dependency.

@ericvergnaud
Copy link
Contributor

It is fixed with #2931

@chapati23
Copy link

great! when's this going to be released? in 4.9 or before?

@fvictorio
Copy link
Author

Hey folks, just as a data point for you: I tried this again and now it seems to work fine!

I had to do some changes:

  • Use the published antlr4 package from npm instead of the generated one
  • Change how the generated modules are imported
  • Extend the classes instead of using Object.create + prototypes

And some other things. But I guess all that will be documented in the release. Thanks for fixing this!

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

7 participants