error "Cannot resolve module 'fs' in ... antlr4/FileStream.js when trying to use JavaScript target

1,456 views
Skip to first unread message

Mike Cargal

unread,
Aug 29, 2016, 5:03:18 PM8/29/16
to antlr-discussion
I see that the antler Javascript target has been added to NPM.

I've added the "antlr4" : "^4.5.2" dependency to my package,son file.

When I try to build through webpack I get the following error:

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


The offending line is

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


I'm going to be running in the browser, so I'm not node.js, but webpack doesn't know which way that ternary statement will evaluate and tries to resolve it.

Any suggestions on how to resolve this?

I'm not sure if it's the require.js (if so, I'm not sure how to reference it.  I'm also using the Babel transpiler for ES2015 syntax, and importing require.js doesn't work)
or if it's the 'fs' module (like the error message indicates.  I've tried adding "fs" to my dependencies as well, but that's not resolving the problem.



anyone have any clues?

Eric Vergnaud

unread,
Sep 18, 2016, 12:08:40 PM9/18/16
to antlr-discussion
Hi
in webpack.config.js, add the following:
module.exports = {
entry: './index.js',
output: {
path: './',
filename: 'your.bundle.js'
},
node: {
module: "empty",
fs: "empty"
}
};
Eric

Mike Cargal

unread,
Sep 20, 2016, 9:59:27 AM9/20/16
to ANTLR List
thanks Eric

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

neha agrawal

unread,
Jan 12, 2017, 3:56:08 PM1/12/17
to antlr-di...@googlegroups.com
Hi,
I got similar error for fileStream.js and Eric solution helped. But unfortunately I am getting similar error at 3 more places. How do I get rid of these errors? Can you please help me.

1)ERROR in ./src/main/resources/myProjectPath/antlr/runtime/Listener.js
 Module not found: Error: Cannot resolve module 'antlr4/index' 

2)ERROR in ./src/main/resources/myProjectPath/antlr/runtime/Lexer.js
 Module not found: Error: Cannot resolve module 'antlr4/index' 

3)ERROR in ./src/main/resources/myProjectPath/antlr/runtime/Parser.js
 Module not found: Error: Cannot resolve module 'antlr4/index' 

Thanks,
Neha


Eric Vergnaud

unread,
Jan 20, 2017, 10:05:29 AM1/20/17
to antlr-discussion
That must be a file path issue.
antlr4/index resolves to antlr4/index.js, which is part of the antlr4 release.
Reply all
Reply to author
Forward
0 new messages