eidellev / inertiajs-adonisjs

280 stars 17 forks source link

Error when trying to lift an ssr server #124

Closed marcelodelta closed 11 months ago

marcelodelta commented 1 year ago

I did all the step by step to run an ssr application, but without success.

config/inertia

export const inertia: InertiaConfig = {
  view: 'app',
  ssr: {
    enabled: true,
    autoreload: process.env.NODE_ENV === 'development'
  },
};

resources/js/ssr.js

import { createSSRApp, h } from 'vue';
import { renderToString } from '@vue/server-renderer';
import {createInertiaApp, Link} from '@inertiajs/vue3';

export default function render(page) {
  return createInertiaApp({
    page,
    render: renderToString,
    resolve: (name) => require(`./Pages/${name}`),
    setup({ app, props, plugin }) {
      return createSSRApp({
        render: () => h(app, props),
      }).use(plugin).component('inertia-link', Link);
    },
  });
}

webpack.ssr.config

Encore.enableVueLoader(() => {}, {
  version: 3,
  runtimeCompilerBuild: false,
  useJsx: false,
})

run the commands

node ace serve --watch node ace ssr:watch

require() of ES Module C:\Users\Projeto\node_modules\@inertiajs\vue3\dist\index.js from C:\Users\Projeto\inertia\ssr\ssr.js not supported. index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in C:\Users\Projeto\node_modules\@inertiajs\vue3\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

marcelodelta commented 1 year ago

Has anyone experienced this problem?

ralphdas commented 12 months ago

Yes, I have the same issue

marcelodelta commented 11 months ago

@ralphdas Did I get it resolved?

ralphdas commented 11 months ago

Short answer, No. Although i'm in a React environment I'am struggling with the same issue. I currently do not have the time to really dive into it. I think these issues might also be resolved sort when Adonis v.6 launches since it's ES modules based opposed to CommonJS.

marcelodelta commented 11 months ago

I believe it will still take a while for version 6. And I need to use it with the ssr function. I've tried everything in my power. I can't solve this transpiler.

marcelodelta commented 11 months ago

@ralphdas

I managed to resolve.

Must be capitalized App

setup({ App, props, plugin }) { return createSSRApp({ render: () => h(App, props), }).use(plugin); },

follow the video
https://www.youtube.com/watch?v=Npn-2qweD5k