javascript - ESlint 编译 es6 导入/导出语句失败

标签 javascript angularjs gulp ecmascript-6 eslint

我正在尝试使用类将我现有的 Angular 应用程序转换为 es6。但是 eslint 在遇到 import/export 语句时无法编译我的 js 文件。

class HeaderController {

    constructor($rootScope, $scope) {
        this.$rootScope = $rootScope;
        this.$scope = $scope;
    }

    changeNavItem(selectedTab) {
        this.activeNavItem = selectedTab;
    }

    init() {
        this.activeNavItem = 'All';
    } }

HeaderController.$inject = ['$rootScope', '$scope'];

angular.module('app')
    .controller('HeaderController', HeaderController);

export default HeaderController; // fails on this line

ESlint 抛出这个错误'由于解析错误无法处理源 'import' 和 'export' 可能只出现在 'sourceType: module''

我已经为 ESlint 添加了必要的配置,但仍然失败。

我在我的 eslintrc.json 中添加了以下内容

"parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "module",
        "allowImportExportEverywhere": true,
        "ecmaFeatures": {
            "modules": true,
            "arrowFunctions": true,
            "classes": true
        }
    }

请帮助我如何解决这个问题,还有一个用 gulp 以 Angular 设置 es6 的完整示例将非常有帮助。

最佳答案

请尝试重命名您的 configuration文件从 eslintrc.json.eslintrc.json

关于javascript - ESlint 编译 es6 导入/导出语句失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38429478/

相关文章:

javascript - onClick触摸版

javascript - Controller 连接到指令进行验证

javascript - 无法在jqGrid中添加按钮点击事件

javascript - 什么是随机替换百度统计(Analytics)的Javascript代码来对浏览器上的网站进行DDOS攻击?

javascript - 如何访问 Controller 内指令的 Controller $scope 属性

javascript - 当用户点击他的子元素时如何防止父点击事件? AngularJS

javascript - 内部错误 : Invalid UTF-8 - Sass & Gulp

javascript - 使用 Critical 和 Gulp 为每个 *.HTML 文件生成 Critical CSS

npm - .node-gyp/4.1.2/common.gypi 未找到

javascript - 如何在 CoffeeScript 中导入 javascript 库?