Vue.js eslint Parsing error .: unexpected token

16,835

Turn on ES6:

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

should be:

  parserOptions: {
    parser: 'babel-eslint',
    ecmaVersion: 6
  },
Share:
16,835
Admin
Author by

Admin

Updated on June 28, 2022

Comments

  • Admin
    Admin almost 2 years

    I am getting this error on a state.js file ( at => in the const profile ) cannot understand why ... thanks for feedback

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

    standard eslint conf from vue-cli . webpack init

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

    the error

    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'
    
  • Admin
    Admin about 6 years
    Thanks a lot... help for single state.js file , no error using modules
  • Jay Bienvenu
    Jay Bienvenu almost 5 years
    This isn't working for me. I tried ecmaVersion set to 6 and to 2017.
  • SSBakh
    SSBakh over 3 years
    Just in case someone made the same mistake as me, I got a Unexpected token in JSON at position error when I tried running yarn install which was easily fixed by removing the comma at the end of "ecmaVersion": 6