【问题标题】:Vue.js eslint Parsing error .: unexpected tokenVue.js eslint 解析错误 .: 意外令牌
【发布时间】:2018-08-14 05:16:57
【问题描述】:

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

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。 webpack 初始化

.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'

【问题讨论】:

    标签: javascript vue.js eslint


    【解决方案1】:

    开启 ES6:

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

    应该是:

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

    【讨论】:

    • 非常感谢...帮助单个 state.js 文件,使用模块没有错误
    • 这对我不起作用。我尝试将ecmaVersion 设置为62017
    • 以防万一有人犯了和我一样的错误,我在尝试运行yarn install 时遇到了Unexpected token in JSON at position 错误,通过删除"ecmaVersion": 6 末尾的逗号很容易解决此问题跨度>
    猜你喜欢
    • 2021-01-15
    • 2022-01-02
    • 2019-12-25
    • 2017-11-21
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    相关资源
    最近更新 更多