我正在尝试使用类将我现有的 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/