I am creating a mock website for a small project that I am doing. I am using nunjucks to perform some tasks. When I try to create a .js file that I can run later, I am getting errors.
I have looked online, and tried every solution out there. I couldn't get any of them to work.
My Code:
const nunjucks = require('nunjucks');
const fs = require('fs'); // The file system module
let files = ["index.html", "About.html", "Membership.html", "Fighting%20Kites.html"];
let srcDir = "./content/";
let outDir = "./output/";
// Tells nunjucks where to look for templates and set any options
nunjucks.configure('views', { autoescape: true });
for (let fname of files) {
let contents = fs.readFileSync(srcDir + fname);
let outString = nunjucks.render('base.njk', {mainContent: contents});
fs.writeFileSync(outDir + fname, outString);
console.log(`Wrote file: ${fname}`);
}
My Error Messages:
JSLint (2)
1 Expected an identifier and instead saw 'const'. const nunjucks = require('nunjucks');
1 Stopping. (10% scanned). const nunjucks = require('nunjucks');
ESLint (1)
1 ERROR: Parsing error: The keyword 'const' is reserved const nunjucks = require('nunjucks');
I have no idea how to fix this. Any ideas help.
const
is a ES6 JavaScript feature. Try enabling the ES6 syntax for Eslint:
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
}
}