【问题标题】:ESlint fails on compiling es6 import/export statementsESlint 在编译 es6 导入/导出语句时失败
【发布时间】:2016-11-20 15:12:26
【问题描述】:

我正在尝试使用类将我现有的 Angular 应用程序转换为 es6。但是 eslint 在遇到导入/导出语句时无法编译我的 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 以角度设置 es6 的完整示例将非常有帮助。

【问题讨论】:

    标签: javascript angularjs gulp ecmascript-6 eslint


    【解决方案1】:

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

    【讨论】:

    • 是的,我的文件命名正确,即 .eslintrc.json
    猜你喜欢
    • 2020-05-13
    • 2015-02-09
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    • 2020-07-25
    • 1970-01-01
    • 1970-01-01
    • 2017-05-28
    相关资源
    最近更新 更多