Tell us about your environment
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
}
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
}
};
works
but i think it may be built in...
Vuepress recommends dynamic imports for certain non-SSR friendly situations. Is there a way to disable this rule by default?
This is not a rule. It happens in the parsing phase and ESLint doesn't support Stage 3 features by default.
+ parser: "babel-eslint", parserOptions: { sourceType: 'module', allowImportExportEverywhere: true }
parser should go before parserOptions, not inside it.
Most helpful comment
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?