JavaScript中的动态导入:使用变量会导致严重的依赖关系:依赖关系的请求是一个表达式

问题描述 投票:0回答:1

简而言之:当动态导入这样的组件时:

var path = '/views/frontend/Study.vue'
const Component = await import(path)

我收到以下错误:

关键依赖项:依赖项的请求是一个表达式

但是如果参数是字符串,则为const Component = await import('/views/frontend/Study.vue')它工作正常

webpack版本:3.8.1

。babelrc中,我正在使用syntax-dynamic-import插件。

更多详细信息:如果您想查看整个图片,这是更多代码...

在Vue路由器中

createView =  (path)=> ()=> import('../components/prefetcher').then(m=>m.default(path))

{ path: '/study',
  name: 'study',
  component: createView('path/to/my/component')
 }

prefetcher.js(上面的createView函数调用导入的内容)

export default async function createView (path) {
  const Component = await import(path) // <<<< works fine when using '/path/to/my/component'
   asyncData ({ store }) {
     store.dispatch("SOME_ACTION")
   },
    render (h) {
      return h(Component.default, { props: { type:extraData.type }})
    }
}
javascript webpack babel
1个回答
0
投票
您是否找到了解决问题的方法?我有完全相同的行为。预先谢谢你。

更新:幸运地找到了这张票:https://github.com/airbnb/babel-plugin-dynamic-import-node/issues/90

© www.soinside.com 2019 - 2024. All rights reserved.