Hello all,
I’m trying to make SSR work using vue 2, vite, and Netlify functions.
I’m able to make it work outside of Netlify functions, but I’m not able to make it work inside a Netlify function.
The problem comes from a lazy loaded route not properly bundled inside the Netlify function
I’ve made a minimal reproduction on this repository :
Steps to reproduce :
git clone git@github.com:sydney-d/vue2-vite-ssr.git
cd vue2-vite-ssr/front
npm install
You can then run either the following (that works):
npm run build && npm run preview:server
If you open : http://localhost:3002/regular it works
If you open : http://localhost:3002/lazy it works
Or run the following (that doesn’t work) :
netlify dev
If you open : http://localhost:8888/regular it works
If you open : http://localhost:8888/lazy it fails
The suspect
It fails because of how this module import is bundled by netlify :
It is being bundled and imported this way :
{ path: "/lazy", component: () => Promise.resolve().then(() => (init_Lazy_727d3bac(), Lazy_727d3bac_exports)) }
Whereas in the working scenarion it is being bundled and imported this way :
{ path: "/lazy", component: () => import("./assets/Lazy-727d3bac.js") }
You can also directly reproduce the bug on Netlify :
Works : https://main--lustrous-kringle-485ab9.netlify.app/regular
Fails : https://main--lustrous-kringle-485ab9.netlify.app/lazy
What I tried
- I tried playing with
node_bundler = "esbuild"
andnode_bundler = "zisi"
- I also tried renaming my function to
index.mjs
orindex.cjs
- And I also try without and without
type: 'module"
in my package.json.
Strangely none of these seemed to have any effect at all, the bundled file always seemed the same.
I tried my best to facilitate your investigation, I hope you’ll be able to help me.
Thanks