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

Consider bumping ESLint ecmaVersion from 2019 to 2020 #2984

Closed
josefaidt opened this issue Dec 5, 2021 · 0 comments
Closed

Consider bumping ESLint ecmaVersion from 2019 to 2020 #2984

josefaidt opened this issue Dec 5, 2021 · 0 comments
Labels

Comments

@josefaidt
Copy link
Contributor

josefaidt commented Dec 5, 2021

Describe the problem

On a fresh SvelteKit project we are unable to use import.meta.env in JS files due to an ESLint error:

1:13  error  Parsing error: Unexpected token import

✖ 1 problem (1 error, 0 warnings)

Bumping ecmaVersion to 2020 fixes this issue.

Reproduction

  1. npm init svelte@next my-app, use ESLint
  2. Create a sample file src/lib/my-file.js with the following content
    // src/lib/my-file.js
    console.log(import.meta.env)
  3. Run ESLint on the new file pnpm eslint src/lib/my-file.js
  4. Observe ESLint error on unexpected token import
  5. Change ESLint ecmaVersion to 2020
  6. Run ESLint on the new file again
  7. Observe no error

image

Describe the proposed solution

module.exports = {
  root: true,
  extends: ['eslint:recommended', 'prettier'],
  plugins: ['svelte3'],
  overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
  parserOptions: {
    sourceType: 'module',
-   ecmaVersion: 2019
+   ecmaVersion: 2020
  },
  env: {
    browser: true,
    es2017: true,
    node: true
  }
}

Alternatives considered

Previously I had just used babel-eslint for the parser, however upon further investigation simply bumping the ecmaVersion mitigates the issue

Importance

nice to have

Additional Information

It is worth noting we can use import.meta.env regardless of ecmaVersion while building our SvelteKit site, however this issue only arises during lint.

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

No branches or pull requests

3 participants