Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module' #462

Closed
TitanNano opened this issue Mar 1, 2016 · 10 comments

Comments

@TitanNano
Copy link

I get this error since the most recent update. is it possible there this is missing somewhere in the package?

@IanVS
Copy link
Member

IanVS commented Mar 1, 2016

Are you using import or export? If so, what is your config file? And, how are you using ESLint (installed in your project, globally, or using the version packaged with linter-eslint), and what version of ESLint are you using?

My first guess is that you need to add

{
    "parserOptions": {
        "sourceType": "module",
    }
}

to your config file.

@TitanNano
Copy link
Author

yes thank you, that solved the issue! 👍

My eslint config is:

{
    "ecmaFeatures": {
        "modules": true,
        "spread" : true,
        "restParams" : true
    },
    "env" : {
        "browser" : true,
        "node" : true,
        "es6" : true
    },
    "rules" : {
        "no-unused-vars" : 2,
        "no-undef" : 2
    },
    "parserOptions": {
        "sourceType": "module"
    }
}

and I'm using the packaged version.

@IanVS
Copy link
Member

IanVS commented Mar 1, 2016

We recently upgraded the packaged version from ESLint 1.x to 2.x, which had some breaking changes in the way configurations should be written. Check out ESLint's migration docs for more details.

@only-vegetarian

This comment has been minimized.

@saahil0826
Copy link

HI just a question on es lint. what is the standard way of setting it up? just install the package from atom or setting up es lint locally for each and every project.

@Arcanemagus
Copy link
Member

HI just a question on es lint. what is the standard way of setting it up?

There are many guides out there, ESLint has their own here: https://eslint.org/docs/user-guide/getting-started

just install the package from atom or setting up es lint locally for each and every project.

This package is only meant to be a wrapper around ESLint, you should be setting it up in projects so:

  • Others working on the project get the same linting configuration
  • When you come back to the project later, you don't have to figure out why your code has suddenly started showing errors when it was "fine" before... at least until you update your lint configuration.

I'm locking this issue as the original report has been resolved.

@webjohnjiang

This comment has been minimized.

@staghouse

This comment has been minimized.

@CristianCuartas

This comment has been minimized.

@jtakalai
Copy link

jtakalai commented Sep 8, 2021

Unrelated (thanks for the parserOptions tip!), adding "plugin:@typescript-eslint/recommended" under "extends" also seemed to solve a bunch of Parsing error: Unexpected token : for me (in very vanilla JS object notation), so that's also something you might want to add when linting typescript.

moylop260 added a commit to vauxoo-dev/pre-commit-vauxoo that referenced this issue Nov 2, 2022
Fix the following error

  Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

Fixing using the following solution:
  AtomLinter/linter-eslint#462 (comment)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants