Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error Parsing error: Unexpected token import #204

Closed
iztsv opened this issue Oct 8, 2017 · 11 comments
Closed

error Parsing error: Unexpected token import #204

iztsv opened this issue Oct 8, 2017 · 11 comments

Comments

@iztsv
Copy link

iztsv commented Oct 8, 2017

Tell us about your environment

  • ESLint Version: 4.8.0
  • eslint-plugin-vue Version: 3.13.0
  • Node Version: 7.5.0

Please show your full configuration:

module.exports = {
  root: true,
  parserOptions: {
    sourceType: 'module',
    ecmaVersion: 8,
  },
  extends: [
    'standard',
    'plugin:vue/recommended' // or 'plugin:vue/base'
  ],
  "env": {
    "browser": true,
  },
  // add your custom rules here
  'rules': {
    "indent": ["error", 2],
    "semi": ["error", "always"],
    "space-before-function-paren": ["error", "never"],
    // allow paren-less arrow functions
    'arrow-parens': 0,
    // allow async-await
    'generator-star-spacing': 0,
    // allow debugger during development
    'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
    // trailing comma
    'comma-dangle': ['error', 'always-multiline'],
  }
}

What did you do? Please include the actual source code causing the issue.

<template>
  <div id="app">
  </div>
</template>

<script>
export default {
  name: 'app2',
  components: {
    'component1': () => import('./components/Component1.vue'),
  },
  data() {
    return {
      isShowComponent: false,
    };
  },
  methods: {
    showComponent: function(event) {
      this.isShowComponent = true;
    },
  },
};
</script>

<style scoped lang="scss">
</style>

What did you expect to happen?

What actually happened? Please include the actual, raw output from ESLint.
src/App.vue 16:25 error Parsing error: Unexpected token import

@iztsv
Copy link
Author

iztsv commented Oct 8, 2017

Sorry for the issue. I missed "parser": "babel-eslint" option in my .eslintrc.js config.
Please, close the issue.

@michalsnik
Copy link
Member

No problem, glad you figured it out :)

@shmarts
Copy link

shmarts commented Mar 17, 2018

I seem to be having this issue when I use the updated parserOptions: { parser: 'babel-eslint' } instead of the old 'parser': 'babel-eslint' format, but appending the old option right above parserOptions fixes it. Is this meant to be happening?

@iztsv
Copy link
Author

iztsv commented Mar 18, 2018

@shmarts parser is not a property of parserOptions. It's separate property for config:

{
  "parser": "babel-eslint",
  "parserOptions": {
    "sourceType": "module",
    "allowImportExportEverywhere": false,
    "codeFrame": false
  }
}

@shmarts
Copy link

shmarts commented Mar 18, 2018

Hmm, a week ago I was getting an error when parser wasn't within parserOptions, but I've removed a couple of eslint related packages recently and it's gone now.

@bjornbos
Copy link

Actually, you do need to set it as a property of parserOptions, have a look at https://github.com/vuejs/eslint-plugin-vue#what-is-the-use-the-latest-vue-eslint-parser-error

@pxwee5
Copy link

pxwee5 commented Dec 11, 2018

Adding "parser": "babel-eslint" will cause babel to highlight the template tag in Single File Components.

@armano2
Copy link
Collaborator

armano2 commented Dec 11, 2018

https://vuejs.github.io/eslint-plugin-vue/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error

- "parser": "babel-eslint",
  "parserOptions": {
+     "parser": "babel-eslint",
      "ecmaVersion": 2017,
      "sourceType": "module"
  }

gsw945 referenced this issue in gsw945/iview-demo4edu01 Jan 7, 2019
@hzsrc
Copy link

hzsrc commented Jul 14, 2019

I don't use vue in a project, but I get the same issue: Parsing error: Unexpected token import
Then I add eslint-plugin-vue to my .eslintrc file, and the error got disappeared!
What a supprise!

@mkantautas
Copy link

@hzsrc Can you please share your .eslintrc.json content?

@jerrychong25
Copy link

https://vuejs.github.io/eslint-plugin-vue/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error

- "parser": "babel-eslint",
  "parserOptions": {
+     "parser": "babel-eslint",
      "ecmaVersion": 2017,
      "sourceType": "module"
  }

This is working, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants