spatie / laravel-server-side-rendering

Server side rendering JavaScript in your Laravel application
https://sebastiandedeyne.com/posts/2018/server-side-rendering-javascript-from-php
MIT License
661 stars 64 forks source link

vue3 support #83

Closed stetim94 closed 2 years ago

stetim94 commented 3 years ago

Could this package work for vue3? I tried:

// resources/js/app.js

import Vue, {createApp} from 'vue';
import TemplateExport from "./components/TemplateExport";

const app = createApp({
    template: {
        TemplateExport,
    }
})
// const app = new Vue({
//     render: h => h(TemplateExport),
// });

export default app;
// resources/js/app-server.js

import app from "./app-client";
import renderVueComponentToString from "vue-server-renderer/basic";

renderVueComponentToString(app, (err, html) => {
    if (err) {
        throw new Error(err);
    }

    dispatch(html);
});
// resources/js/client-server.js

import app from './app';

app.mount('#app');

but this results in an error:

The command "/usr/bin/node /application/storage/app/ssr/c1d33d05b83783d3ec4888829f1e8e82.js" failed. Exit Code: 1(General error) Working directory: /application/public Output: ================ Error Output: ================ /application/storage/app/ssr/c1d33d05b83783d3ec4888829f1e8e82.js:43696 const res = document.querySelector(container); ^ ReferenceError: document is not defined at normalizeContainer (/application/storage/app/ssr/c1d33d05b83783d3ec4888829f1e8e82.js:43696:21) at Object.app.mount (/application/storage/app/ssr/c1d33d05b83783d3ec4888829f1e8e82.js:43654:27) at Module../resources/assets/js/app-client.js (/application/storage/app/ssr/c1d33d05b83783d3ec4888829f1e8e82.js:44409:43) at __webpack_require__ (/application/storage/app/ssr/c1d33d05b83783d3ec4888829f1e8e82.js:67965:42) at /application/storage/app/ssr/c1d33d05b83783d3ec4888829f1e8e82.js:68038:69 at /application/storage/app/ssr/c1d33d05b83783d3ec4888829f1e8e82.js:68051:3 at Object.<anonymous> (/application/storage/app/ssr/c1d33d05b83783d3ec4888829f1e8e82.js:68053:12) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) (View: /application/resources/views/test.blade.php) 
spatie-bot commented 2 years ago

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.