【问题标题】:Troubles with using gulp-eslint使用 gulp-eslint 的问题
【发布时间】:2019-09-27 17:29:18
【问题描述】:

我正在尝试将 gulp-eslint 添加到我的构建过程中,让 gulp 监视我的文件并在文件更改时运行 eslint。但是,我收到一条错误消息:

D:\code\project\node_modules\gulp-eslint\index.js:4
const {CLIEngine} = require('eslint');
  ^

SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:413:25)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (D:\code\project\gulpfile.js:5:16)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)

当我尝试运行我编写的 ESLint 任务时。

这里是 eslint 任务的代码:

gulp.task('eslint', () => {

   return gulp.src(lintscripts)

    .pipe(eslint({
        "env": {
            "browser": true,
            "node": true,
            "commonjs": true,
            "es6": true
        },
        "extends": "eslint:recommended",
        "parserOptions": {
            "sourceType": "module",
            "ecmaVersion": 2017
        },
        "rules": {
            'no-console': 'off',
            'indent' : 'off',
            "semi": [
                "error",
                "always"
            ]
        }
    })).pipe(eslint.format());

});

【问题讨论】:

  • 看起来你的 js 环境不支持解构语法?
  • 'const CLIEngine = require('eslint').CLIEngine' 工作吗?

标签: javascript gulp browserify eslint gulp-eslint


【解决方案1】:

请检查您的节点版本。您正在使用 Node v6 提供的对象解构。如果您使用的是 node v4,那么这可能不起作用。

【讨论】:

    猜你喜欢
    • 2020-01-28
    • 2016-07-23
    • 1970-01-01
    • 2016-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-12
    • 1970-01-01
    相关资源
    最近更新 更多