Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to load module for ssr #3087

Closed
dongnaebi opened this issue Apr 22, 2021 · 1 comment · Fixed by #3177
Closed

failed to load module for ssr #3087

dongnaebi opened this issue Apr 22, 2021 · 1 comment · Fixed by #3177

Comments

@dongnaebi
Copy link

Describe the bug

when I using dynamic import like this:

function load (component) {
  return () => import(`../pages/${component}.vue`)
}

export default [
  {
    path: '/',
    component: load('index'),
    meta: { title: '首页' }
  }
]

I got an error: Error: failed to load module for ssr: ../pages/index.vue

but it can work like this:

export default [
  {
    path: '/',
    component: () => import('../pages/index.vue'),
    meta: { title: '首页' }
  }
]

Reproduction

https://github.com/dongnaebi/vite-ssr-repro

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

  System:
    OS: Windows 10 10.0.19041
    CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
    Memory: 8.10 GB / 15.88 GB
  Binaries:
    Node: 14.4.0 - D:\Program Files\nodejs\node.EXE
    npm: 6.14.5 - D:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 89.0.4389.128
    Edge: Spartan (44.19041.906.0), Chromium (90.0.818.42)
    Internet Explorer: 11.0.19041.1

Used package manager: npm

Logs

Error: failed to load module for ssr: ../pages/index.vue
    at instantiateModule (E:\project\jiuyun-pc\node_modules\vite\dist\node\chunks\dep-5c642f9e.js:68989:15)
Error: Couldn't resolve component "default" at "/"
    at E:\project\jiuyun-pc\node_modules\vue-router\dist\vue-router.cjs.js:1998:47
(node:4672) UnhandledPromiseRejectionWarning: Error: Couldn't resolve component "default" at "/"
    at E:\project\jiuyun-pc\node_modules\vue-router\dist\vue-router.cjs.js:1998:47
(node:4672) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). T
o terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 16)

Before submitting the issue, please make sure you do the following

  • [ x ] Read the Contributing Guidelines.
  • [ x ] Read the docs.
  • [ x ] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [ x ] Provide a description in this issue that describes the bug.
  • [ x ] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
  • [ x ] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
@Shinigami92
Copy link
Member

This may be fixed by #2934 🤔
Could you try this branch? (build locally and use yarn link)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants