Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 97355

VSCode ESLint howto fix parsing error: 'import' and 'export' may only appear at the top level

$
0
0

When doing a dynamic import:

if (true) import x from 'y'; //Parsing error: 'import' and 'export' may only appear at the top level

my .eslintrc

{
  "root": true,
  "extends": "eslint:recommended",
  "env": {
    "es6": true,
    "node": true,
    "browser": true
  },
  "parserOptions": {
    "ecmaVersion": 10,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "rules": {
    "strict": 0,
    "no-undef": 2,
    "accessor-pairs": 2,
    "comma-dangle": [2, "always-multiline"],
    "consistent-return": 2,
    "dot-notation": 2,
    "eqeqeq": 2,
    "indent": [2, 2, {"SwitchCase": 1}],
    "no-cond-assign": 2,
    "no-constant-condition": 2,
    "no-eval": 2,
    "no-inner-declarations": [0],
    "no-unneeded-ternary": 2,
    "radix": 2,
    "semi": [2, "always"],
    "camelcase": 2,
    "comma-spacing": 2,
    "comma-style": 2,
    "eol-last": 2,
    "linebreak-style": [2, "unix"],
    "new-parens": 2,
    "no-lonely-if": 2,
    "no-multiple-empty-lines": 2,
    "no-nested-ternary": 2,
    "no-spaced-func": 2,
    "no-trailing-spaces": 2,
    "operator-linebreak": 2,
    "quotes": [2, "single"],
    "semi-spacing": 2,
    "space-unary-ops": 2,
    "arrow-parens": 2,
    "arrow-spacing": 2,
    "no-class-assign": 2,
    "no-dupe-class-members": 2,
    "no-var": 2,
    "object-shorthand": 2,
    "prefer-const": 2,
    "prefer-spread": 2,
    "prefer-template": 2
  },

i already tried:
...switching ecmaVersion to, 11, 2018, 2019, 2020 which give me either wrong number or parser didn't work anymore
...added parser: babel-eslint which make the parser not work anymore
...added allowImportsExportsAnywhere: true which did nothing


Viewing all articles
Browse latest Browse all 97355

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>