ESlint在编译ES6的import/export语句时失败了。

3

我正在尝试使用类将我的现有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的例子,那将非常有帮助。
1个回答

0
请尝试将您的配置文件从eslintrc.json重命名为.eslintrc.json

是的,我的文件命名正确,即 .eslintrc.json。 - Abhidev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接