Skip to content
Advertisement

Two output files share the same path but have different contents

I’ve come across this error when building grammar for a parser, using nearley.js. I have three files: grammar.ne, grammar.js, and parser.js. The full error is below:

JavaScript

Here are the contents of each of the files:

grammar.ne:

JavaScript

grammar.js:

JavaScript
JavaScript

Nothing that I have found online has helped at all. This is built in a TypeScript repl, and I have a lexer written in TypeScript, if that helps any.

Advertisement

Answer

I figured out the issue. In my package.json, I had used the module "es2015" when I should have been using "commonjs". I then changed the file extension of grammar.js to .cjs, and that got rid of all of the automatically-generated code errors. I also added a script to the package json npx nearleyc grammar.ne -o grammar.cjs && node parser.cjs, which allows me to execute compiling the grammar file faster, and uses the new .cjs extension to compile it to a CommonJS module; this also allows me to run the test file at the same time.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement