Parsing error: Unexpected token `import`

See original GitHub issue
  • ESLint Version: 5.10.0
  • Node Version: 11.4.0
  • npm Version: 6.4.1

What parser (default, Babel-ESLint, etc.) are you using?

Default.

Please show your full configuration:

Configuration
{
  "extends": "eslint",
  "parserOptions":{
    "ecmaVersion": "2018",
    "sourceType": "module"
  }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

// Workaround for `--experimental-modules`
// See <https://nodejs.org/docs/latest/api/esm.html#esm_import_meta>
const __dirname = Path.dirname(new URL(import.meta.url).pathname)
eslint sample.mjs

What did you expect to happen?

A decent report.

What actually happened? Please include the actual, raw output from ESLint.

  3:40  error  Parsing error: Unexpected token import

✖ 1 problem (1 error, 0 warnings)

Are you willing to submit a pull request to fix this bug?

No.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
seamlikcommented, Dec 12, 2018

Now with this config:

{
  "extends": "standard",
  "parser": "babel-eslint"
}

and installing babel-eslint, the error was gone. Thanks for the solution!

Though I personally can’t consider this ticket is resolved. But I’ll leave the decision to you guys.

1reaction
kaicataldocommented, Dec 12, 2018

@seamlik That’s right. Currently, the solution is to use the babel-eslint parser. That being said, there are plans to change babel-eslint to expect babel as a peer dependency. The assumption is that anyone using babel-eslint is also using babel, but you’ve hit a case where that isn’t true.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Imports for Code Splitting cause: ESLint Parsing ...
My code runs and works as expected when using npm run dev and npm run build , but this parsing error prevents the...
Read more >
ESLint Parsing error: Unexpected token - rockyourcode
ESLint Parsing error: Unexpected token. ESLint throws some errors: error Parsing error: The keyword 'import' is reserved or, when using JSX: ...
Read more >
eslint/eslint - Gitter
I'm using sourceType module.. but still getting error Parsing error: Unexpected token import. Kevin Partington. @platinumazure.
Read more >
[ESLint] Parsing error: unexpected token - DEV Community ‍ ‍
This is a solution when I saw these errors. ... Warning: React version not specified in eslint-plugin-react settings. See https://github.com/ ...
Read more >
import.meta.url - Parsing error: Unexpected token import
You received this message because you are subscribed to the Google Groups "ESLint" group. To unsubscribe from this group and stop receiving ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found