JSLint 和 ESLint 问题(括号)

JSLint and ESLint Problems (Brackets)

我正在为我正在做的一个小项目创建一个模拟网站。我正在使用 nunjucks 来执行一些任务。当我尝试创建一个我可以稍后 运行 的 .js 文件时,我遇到了错误。

我在网上看过,并尝试了所有解决方案。我无法让他们中的任何一个工作。

我的代码:

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}`);
}

我的错误信息:

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');

我不知道如何解决这个问题。任何想法都有帮助。

const 是 ES6 JavaScript 特性。尝试为 Eslint 启用 ES6 语法:

{
    "parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "module",
    }
}