Vue.js 3 模板文字错误 无法读取 属性 'range' of null

Vue.js 3 template- literals error Cannot read property 'range' of null

我正在尝试在 Vue.js 中动态导入一个异步组件。

<template>
  <MyAsync></MyAsync>
</template>

<script>
import { defineAsyncComponent } from 'vue';

const component = 'lorem-ipsum-4';

export default {
  name: 'Article',
  components: {
    MyAsync: defineAsyncComponent(() => import(`@/articles/${component}.vue`)),
  },
};
</script>

但这不起作用并产生以下错误。

Failed to compile.

./src/views/Article.vue
Module build failed (from ./node_modules/eslint-loader/index.js):
TypeError: Cannot read property 'range' of null
Occurred while linting /project/src/views/Article.vue:13
    at SourceCode.getTokenBefore (/project/node_modules/eslint/lib/source-code/token-store/index.js:298:18)
    at checkSpacingBefore (/project/node_modules/eslint/lib/rules/template-curly-spacing.js:60:42)
    at TemplateElement (/project/node_modules/eslint/lib/rules/template-curly-spacing.js:119:17)
    at /project/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/project/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/project/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/project/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/project/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/project/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:634:23)
    at /project/node_modules/eslint/lib/linter/linter.js:936:32
    at Array.forEach (<anonymous>)
    at runRules (/project/node_modules/eslint/lib/linter/linter.js:931:15)
    at Linter._verifyWithoutProcessors (/project/node_modules/eslint/lib/linter/linter.js:1157:31)
    at /project/node_modules/eslint/lib/linter/linter.js:1281:29
    at Array.map (<anonymous>)

然而静态导入工作得很好:

<template>
  <MyAsync></MyAsync>
</template>

<script>
import { defineAsyncComponent } from 'vue';

export default {
  name: 'Article',
  components: {
    MyAsync: defineAsyncComponent(() => import('@/articles/lorem-ipsum-4.vue')),
  },
};
</script>

这是一个使用 Vue CLI 创建的 Vue.js v3 项目。

可以在 github

找到一个(非常小的)示例

有没有办法使动态导入工作?

export default {
  name: 'Article',
  components: {
    MyAsync: defineAsyncComponent(() => import('@/articles/'+ component +'.vue')),
  },
};

但是,我觉得这样不好。

在由./

组成的路径上替换@
export default {
  name: 'Article',
  components: {
    MyAsync: defineAsyncComponent(() => import(`./articles/${component}.vue`)),
  },
};

对我有用

经过一些调试我发现它是一个 eslint issue template-curly-spacing,为了解决这个问题,我将文件 .eslintrc 添加到项目根目录,内容如下:

{
    "plugins": [
        "vue"
      ],
    "rules" : {
        "template-curly-spacing": ["error", "never"]
      }
}