server icon indicating copy to clipboard operation
server copied to clipboard

createServer is not a function

Open MtDalPizzol opened this issue 3 years ago • 5 comments

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

MtDalPizzol avatar Jul 31 '22 15:07 MtDalPizzol

Same here, when I run a Laravel Vite build

Xor767 avatar Aug 01 '22 08:08 Xor767

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'],
    },
});

timacdonald avatar Aug 09 '22 00:08 timacdonald

Where to put this option?

RomkaLTU avatar Nov 12 '22 11:11 RomkaLTU

In the Vite configuration.

timacdonald avatar Nov 13 '22 22:11 timacdonald

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

noBloodOnTheLeaves avatar Nov 16 '22 20:11 noBloodOnTheLeaves