createServer is not a function
I believe there's a bug related to Node ESM in some scenarios when trying to lift the SSR server that causes the createServer function to be undefined.
How to reproduce:
Run vite build && vite build --ssr
Run node bootstrap/ssr/ssr.mjs
Node version: 18.4.0 Package version: 0.1.0
How to workaround
import createServer from '@inertiajs/server';
createServer.default((page) => // Adding .default here solved the problem for me, but it shouldn't be necessary
Same here, when I run a Laravel Vite build
FYI: In the Laravel Jetstream, we solve this by not externalising the server.
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [
laravel({
// ...
}),
// ...
],
ssr: {
noExternal: ['@inertiajs/server'],
},
});
Where to put this option?
In the Vite configuration.
in my case, i used ssr.jsx in input of laravel function call (-_-')\
plugins: [
laravel({
input: 'resources/js/ssr.jsx', // -> need input: 'resources/js/app.jsx'
ssr: 'resources/js/ssr.jsx',
refresh: true,
}),
react(),
],
server: {
hmr: {
host: 'localhost',
},
},
ssr: {
noExternal: ['@inertiajs/server'],
},
You can check some configuration in Jetstream, like i did after read @timacdonald comment