javascript - Uncaught Error: Module name "antlr4/index" has not been loaded yet for context on require.js -


i try use antlr4 on javascript, read https://tomassetti.me/antlr-and-the-web/ , make error has occurred.

index.html

<!doctype html> <html lang="en"> <head>     <meta charset="utf-8">     <title>title</title>     <script type="text/javascript" src="lib/require.js"></script>     <script type="text/javascript">         var antlr4 = require('antlr4/index');         var querylexer = require('gram/querylexer');         var queryparser = require('gram/queryparser');         document.getelementbyid("parse").addeventlistener("click", function() {             var input = document.getelementbyid("code").value;             var chars = new antlr4.inputstream(input);             var lexer = new querylexer.querylexer(chars);             var tokens = new antlr4.commontokenstream(lexer);             var parser = new queryparser.queryparser(tokens);             parser.buildparsetrees = true;             var tree = parser.query();             console.log("parsed: "+ tree);         });     </script> </head> <body> <div id="inputs"> <textarea id="code"> * play antlr4 * write tutorial </textarea>     <br/>     <button id="parse">parse</button> </div> </body> </html> 

the error may cause on "var antlr4 = require('antlr4/index');". downloaded antlr4 http://www.antlr.org/download/index.html , put same tier of "index.html". in lib directory there exist "require.js".

index.js

exports.atn = require('./atn/index'); exports.codepointat = require('./polyfills/codepointat'); exports.dfa = require('./dfa/index'); exports.fromcodepoint = require('./polyfills/fromcodepoint'); exports.tree = require('./tree/index'); exports.error = require('./error/index'); exports.token = require('./token').token; exports.charstreams = require('./charstreams').charstreams; exports.commontoken = require('./token').commontoken; exports.inputstream = require('./inputstream').inputstream; exports.filestream = require('./filestream').filestream; exports.commontokenstream = require('./commontokenstream').commontokenstream; exports.lexer = require('./lexer').lexer; exports.parser = require('./parser').parser; var pc = require('./predictioncontext'); exports.predictioncontextcache = pc.predictioncontextcache; exports.parserrulecontext = require('./parserrulecontext').parserrulecontext; exports.interval = require('./intervalset').interval; exports.utils = require('./utils'); 

i think there no problems, because require path('antlr4/index') not wrong. error has occurred. please give me idea.

the code show in question cannot work as-is requirejs. you'd have write require calls differently, or wrap require calls have in define use commonjs support requirejs provides.

but the tutorial not asking use requirejs. if go github repo writer of tutorial provided, you'll see:

require.js obtained https://github.com/letorbi/smoothie/blob/master/standalone/require.js

you have use file, not requirejs, similar in sense loads scripts, , yet different requirejs in sense seems support commonjs module format as-is, requirejs doesn't.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -