Syntax error: 'import' and 'export' may only appear at the top level - despite putting a rule in ESLint

Viewed 3357

I am trying to turn a React Native app into a React Native Web app as well.

I want to do the following kind of import:

if (Platform.OS !== 'web') {
    import { Route, Link, Switch, push, DeepLinking } from "react-router-native";
}

However I get the error:

Syntax error: 'import' and 'export' may only appear at the top level (16:4)

Now I've tried to add an ESLint configuration in my package.json to prevent this:

  "eslintConfig": {
    "parser": "babel-eslint",
    "parserOptions": {
      "sourceType": "module",
      "allowImportExportEverywhere": true
    }
  }

But it is still happening.

How do I allow dynamic imports?

0 Answers
Related