question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parsing error: 'import' and 'export' may only appear at the top level

See original GitHub issue

Tell us about your environment

  • ESLint Version: 5.4.0
  • eslint-plugin-vue Version: 5.0.0-beta.3
  • Node Version: 10.8

Please show your full configuration:

module.exports = {
  root: true,
  extends: [
    'plugin:vue/recommended',
    'dwing'
  ],
  parserOptions: {
    sourceType: 'module',
    allowImportExportEverywhere: true
  }
};

What did you do? Please include the actual source code causing the issue.

export default {
  name: 'Aplayer',
  mounted() {
    const that = this;
    // error
    import('aplayer').then(({ default: Aplayer }) => {
      
    });
  }
};

What did you expect to happen?

dynamic import for performance

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

{
	"resource": "/Users/willin/Documents/websites/blog/src/.vuepress/theme/components/sidebar/player.vue",
	"owner": "eslint",
	"code": "undefined",
	"severity": 8,
	"message": "Parsing error: 'import' and 'export' may only appear at the top level",
	"source": "eslint",
	"startLineNumber": 12,
	"startColumn": 4,
	"endLineNumber": 12,
	"endColumn": 4
}

Issue Analytics

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

github_iconTop GitHub Comments

6reactions
polkhovskycommented, Nov 21, 2019
+    parser: "babel-eslint",
parserOptions: {
    sourceType: 'module',
    allowImportExportEverywhere: true
  }

parser should go before parserOptions, not inside it.

3reactions
ota-meshicommented, Aug 27, 2018

Dynamic import may not be supported by eslint default parser. It seems to solve by using babel-eslint.

https://github.com/eslint/eslint/issues/9927

Could you try it?

module.exports = {
  root: true,
  extends: [
    'plugin:vue/recommended',
    'dwing'
  ],
  parserOptions: {
+    parser: "babel-eslint",
    sourceType: 'module',
    allowImportExportEverywhere: true
  }
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

'import' and 'export' may only appear at the top level
I'm using webpack with vuejs. Webpack does its thing, but when I look at the outputted app.js file, it gives me this error....
Read more >
'import' and 'export' may only appear at the top level | bobbyhadz
The error "import and export may only appear at the top level" occurs when we forget a closing brace when declaring a function...
Read more >
How to fix: import and export may only appear at the top level
So I've setup a new Svelte project and install all the latest node modules. ... If you're developing a Svelte project, you're probably...
Read more >
'export' may only appear at the top level | Velo by Wix
Hey, I'm getting an error "Modifiers cannot appear here. Parsing error: 'import' and 'export' may only appear at the top level" Here's the ......
Read more >
ESLint - HackingNote
ESLint · Ignore Warning: Parsing error: 'import' and 'export' may only appear at the top level · Ignore Warning: react/prop-types.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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