2
votes

I am trying to use webpack with antlr 4 javascript target. I am following this document. https://github.com/antlr/antlr4/blob/master/doc/javascript-target.md

If I understand correctly , webpack will merge all the files from antlr4 javascript runtime librarty and the generated files (Lexer.js, Listener.js and Parser.js) in one single file. I need to include only this one file in my html.

I don't understand this part of the document where it's asking to exclude node.js module. Can someone please explain why this line is needed?

In the webpack.config file, exclude node.js only modules using: node: { module: "empty", net: "empty", fs: "empty" }

I also don't have any custom listener or visitor. Can I ignore these steps. I am not creating any index.js file with entry point to my parsing code.

  • write your parse tree handling code by providing your custom listener or visitor, and associated code, using 'require' to load antlr.
  • create an index.js file with the entry point to your parsing code (or several if required).**
1
Does this answer your question? How to use antlr if an error with fs occurs?ggorlen

1 Answers

3
votes

I understood why I need this configuration in webpack.config.js. If I don't have this configuration

node: {
        module: "empty",
        net:"empty",
        fs: "empty"
    },

I get below error while running webpack command:-

ERROR in ./~/antlr4/FileStream.js Module not found: Error: Cannot resolve module 'fs' in /node_modules/antlr4 @ ./~antlr4/FileStream.js 38:20-33

The offending line is

var fs = isNodeJs ? require("FS") : null;