javascript - Vue.js eslint 解析错误。 : unexpected token

标签 javascript vue.js eslint

我在 state.js 文件中收到此错误(在 const 配置文件中的 =>) 不明白为什么...感谢反馈

const credentials = {
  email: '',
  password: ''
}
const profile = {
=>    userId: '',
  gender: '',
  firstName: '',
  lastName: '',
  address: '',
  zipCode: '',
  city: '',
  country: 'France',
  musician: false,
  musicInstruments: [],
  yearsPlaying: 0
}
export default {
  credentials,
  profile
}

来自 vue-cli 的标准 eslint conf。网络包初始化

.eslintrc.js

// https://eslint.org/docs/user-guide/configuring

module.exports = {
  root: true,
  parserOptions: {
    parser: 'babel-eslint'
  },
  env: {
    browser: true,
  },
  extends: [
    // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
    // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
    'plugin:vue/essential', 
    // https://github.com/standard/standard/blob/master/docs/RULES-en.md
    'standard'
  ],
  // required to lint *.vue files
  plugins: [
    'vue'
  ],
  // add your custom rules here
  rules: {
    // allow async-await
    'generator-star-spacing': 'off',
    // allow debugger during development
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
  }
}

错误

file: 'file:///Users/yves/Developments/WIP/FIREBASE/vue-firebase-tutorial-store-user/src/store/state.js'
severity: 'Error'
message: 'Parsing error: Unexpected token

[0m [90m 4 | [39m}[0m
[0m [90m 5 | [39m[36mconst[39m profil[0m
[0m[31m[1m>[22m[39m[90m 6 | [39m[36mexport[39m [36mdefault[39m {[0m
[0m [90m   | [39m[31m[1m^[22m[39m[0m
[0m [90m 7 | [39m  credentials[0m
[0m [90m 8 | [39m}[0m
[0m [90m 9 | [39m[0m'
at: '6,1'
source: 'eslint'
code: 'undefined'

最佳答案

开启 ES6:

  parserOptions: {
    parser: 'babel-eslint'
  },

应该是:

  parserOptions: {
    parser: 'babel-eslint',
    ecmaVersion: 6
  },

关于javascript - Vue.js eslint 解析错误。 : unexpected token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49129296/

相关文章:

javascript - 在 TypeScript 和 JavaScript 中使用 ESLint 和 Prettier

javascript - $([]) 在 jQuery 中是什么意思?

Javascript 在 eval 字符串中返回

javascript - Laravel 和 VueJS,访问 Vue 实例。

Eslint 配置显示 `definition for rule ' filenames/match-regex' was not found` 错误

intellij-idea - Intellij "reformat code"命令不遵循更漂亮的规则

javascript - MxGraph 中节点、边和 Canvas 的自定义(不同)右键菜单

javascript - 无法获取内容脚本 Firefox Addon 中的范围

javascript - Vue.js - 串联

vue.js - [Vue警告] : Failed to resolve component: router-view