-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
ssrBuild with async Vue3 components / routes , trouble with import to require conversion in built files. #764
Comments
Related to #720 |
For async component, you should use |
@underfin I tried the same code with defineAsyncComponent, it does not change the way the code is compiled and has the same problem with how import is converted to a require that lacks the default part of the import. |
The compiled behavior is correct, |
@underfin this does not seem to be the case, i might be doing something wrong? export default function (type) {
const routerHistory = type === 'client' ? createWebHistory() : createMemoryHistory();
return createRouter({
history: routerHistory,
routes: [
{ path: '/', component: Home, props: true },
{ path: '/a', component: defineAsyncComponent(() => import("./components/PageA.vue")), props: true },
{ path: '/b', component: defineAsyncComponent(() => import("./components/PageB.vue")), props: true },
]
});
} which is being compiled to: function createRouter$1(type) {
const routerHistory = type === "client" ? createWebHistory() : createMemoryHistory();
return createRouter({
history: routerHistory,
routes: [
{path: "/", component: script$2, props: true},
{path: "/a", component: vue.defineAsyncComponent(() => Promise.resolve().then(function() {
return require("./PageA.161ddab2.js");
})), props: true},
{path: "/b", component: vue.defineAsyncComponent(() => Promise.resolve().then(function() {
return require("./PageB.f65a13cd.js");
})), props: true}
]
});
} When running the server, i'm getting a warning and the page components do not render.
However, when i change
|
Can you provider your repo for me track this? |
@underfin yes, i just set this up https://github.com/tbgse/vite-ssr-example it's super basic, so i completely ignore hydration etc. in this example. But just by running |
…dule during ssr fix #vitejs/vite#764
I try fix it,it is a bug with vue core. You can track here vuejs/core#2034 |
Awesome @underfin I'll keep a close eye on the PR in vue core. |
You shouldn't use |
thanks for jumping in on this @posva with so many moving pieces (router, vue, vite) it was really hard for me to pinpoint where things were going wrong here. I posted a very minimal setup of the repo here: https://github.com/tbgse/vite-ssr-example and just updated it by removing Again this is only a problem when building in vite ssr mode. When you simply build for the client, everything works as expected. |
Thanks, well for some reason the generated module is missing the @underfin I think there might be a bug in the transpilation on SSR: shouldn't the dynamic import output a |
Yeah.It look like lost |
@tbgse .You can add blew code into module.exports = {
rollupInputOptions: {
preserveEntrySignatures: 'strict',
},
rollupOutputOptions: {
preserveModules: true,
},
} |
Thanks @underfin this works fine and hydration works like a charm with it too. It does create a massive amount of files compared to the default settings though, so i'm keeping a close eye on the issue you opened in rollup. |
@underfin following up since rollup/plugins#552 seems to have been merged. I'm not 100% sure if this would need further adjustments in the vite config files (or internally?) or should it now work out of the box with the latest rollup version? |
@underfin @antfu I could not get this to work with the latest It seems like the original issue opened by underfin in the rollup repo was marked as resolved, so this should no longer be an upstream bug. |
I add comment with rollup/rollup#3760 (comment), please wait for answer. |
@underfin it seems like a fix was merged in rollup rollup/rollup#3822 EDIT: it seems to work as expected now by installing the latest version of rollup and adding
to the build config. Would it be possible to update the rollup dependency for vite? |
Describe the bug
I've been spending some time with the mostly undocumented ssrBuild feature of Vite + Vue3, so this might not actually be a bug but working as intended and i might be doing something wrong.
I am trying to run the ssrBuild with a router that defines some async components as below:
However, once i built my entry files with
ssrBuild
it converts the router part in the entry file to:The problem here is how the requires are defined:
The above code does end up not being able to find the component. If i manually go into the built files and add a
.default
behind this, the code works fine and my pages load / hydrate correctly.since the exported pages all have default exports, this seems to be logical. E.g. in PageA:
Is this actually a bug with vite where it should be adding the
.default
to the required components? Am I doing something wrong here and should i define my imports differently? Happy to provide additional info if needed.System Info
vite
version: ^1.0.0-rc.4The text was updated successfully, but these errors were encountered: