2016-07-18 81 views
1

我想使用類將現有的角度應用程序轉換爲es6。但eslint在遇到導入/導出語句時無法編譯我的js文件。ESlint無法編譯es6導入/導出語句

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拋出這個錯誤「無法處理由於源解析錯誤 ‘進口’和‘出口’可能會出現只與‘sourceType的:模塊’

我已經添加了必要的配置ESlint,但仍然失敗。

我已經加入我的eslintrc.json

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

請我怎麼能解決這個問題,也在角設立ES6與一飲而盡將是很有益的一個完整的例子幫助下。

回答

0

請嘗試將您的configuration文件從eslintrc.json更名爲.eslintrc.json

+0

是的,我有正確命名的文件,即.eslintrc.json – Abhidev