Importing PEGJS parser using require and module.exports

893 Views Asked by At

I'm trying to use a PEGJS parser in multiple different files. I use the method var Parser = require("./Parser");

When I try to parse something using Parser.parse, though, I am unable to do so, because Parser is undefined.

How can I fix this? It had been working previously, but I made some changes to my grammar and had to regenerate the parser.

The exact error I get when running it is Uncaught TypeError: Cannot read property 'parse' of undefined

The basic code I'm trying to import is below.

module.exports = (function() {
    //Some other functions
    function parse(input) {
        //Parse code
    },
    //Some other functions
})();

And I'm trying to import this function and use it with

var Parser = require("./Parser");

//Some other code

    Parser.parse(options.queryText)
0

There are 0 best solutions below