Javascript Webpack Problem

146 views
Skip to first unread message

John McKeown

unread,
Jan 27, 2021, 2:50:46 PM1/27/21
to antlr-discussion
I'm getting an error when following the instructions here: https://github.com/antlr/antlr4/blob/master/doc/javascript-target.md

I had this working before using antlr4 version 7.2, but now as the above link says, anltr has switched to using more modern javascript features. One thing this might be yelling at me about is the use of the static keyword, but I tried fixing that by using the babel-loader in webpack, but that just gave me more/different errors.

**How can I configure webpack to work successfully? Perhaps the above link should reflect whatever process is necessary to get antlr to actually work on JS?**

Here is my `webpack.config.js` file:

```javascript
const path = require('path');

module.exports = {
  entry: './static/js/helpers.js',
  output: {
    path: path.resolve(__dirname, 'static/js'),
    filename: 'bundle.js'
  },
  node: { module: "empty", net: "empty", fs: "empty" },
  mode:"development"
};
```

This is the output when I run webpack in the folder containing the `webpack.config.js` file.


```bash

> node_modules/.bin/webpack
Hash: 6ef5eb21384d39f701ec
Version: webpack 4.46.0
Time: 981ms
Built at: 01/27/2021 2:26:32 PM
    Asset     Size  Chunks             Chunk Names
bundle.js  524 KiB    main  [emitted]  main
Entrypoint main = bundle.js
[./TPTP-ANTLR4-Grammar/tptp_v7_0_0_0Lexer.js] 472 bytes {main} [built] [failed] [1 error]
[./TPTP-ANTLR4-Grammar/tptp_v7_0_0_0Listener.js] 41.1 KiB {main} [built]
[./TPTP-ANTLR4-Grammar/tptp_v7_0_0_0Parser.js] 539 bytes {main} [built] [failed] [1 error]
[./static/js/helpers.js] 9.94 KiB {main} [built]
[./static/js/parser.js] 8.26 KiB {main} [built]
    + 48 hidden modules

WARNING in ./static/js/parser.js 112:24-32
"export 'tptp_v7_0_0_0Listener' (imported as 'Listener') was not found in '../../TPTP-ANTLR4-Grammar/tptp_v7_0_0_0Listener'
 @ ./static/js/helpers.js

ERROR in ./TPTP-ANTLR4-Grammar/tptp_v7_0_0_0Parser.js 1046:27
Module parse failed: Unexpected token (1046:27)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| export default class tptp_v7_0_0_0Parser extends antlr4.Parser {
>     static grammarFileName = "tptp_v7_0_0_0.g4";
|     static literalNames = [ null, "'tpi('", "','", "').'", "'thf('", "'tfx('", 
|                             "'tff('", "'tcf('", "'fof('", "'cnf('", "'('", 
 @ ./static/js/parser.js 5:0-94 279:18-24
 @ ./static/js/helpers.js

ERROR in ./TPTP-ANTLR4-Grammar/tptp_v7_0_0_0Lexer.js 475:27
Module parse failed: Unexpected token (475:27)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| export default class tptp_v7_0_0_0Lexer extends antlr4.Lexer {
>     static grammarFileName = "tptp_v7_0_0_0.g4";
|     static channelNames = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN" ];
| static modeNames = [ "DEFAULT_MODE" ];
 @ ./static/js/parser.js 4:0-91 277:17-22
 @ ./static/js/helpers.js
---------------------------------------------------------------------------  

```


Reply all
Reply to author
Forward
0 new messages