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
662 stars 63 forks source link

Error: TypeError: Cannot read property 'render' of undefined #64

Closed zjalen closed 4 years ago

zjalen commented 4 years ago

Npm run build successfully.I have a problem while rendering.I have no idea about the reason cause it.Could someone help me to check.Thank you~

// debug info
Facade\Ignition\Exceptions\ViewException: The command "/usr/local/bin/node /Users/jialinzhang/code/lavuetify-blog/storage/app/ssr/4957fb2b412b1220dbeb1d7e11e781d9.js" failed.

Exit Code: 1(General error)

Working directory: /Users/jialinzhang/code/lavuetify-blog/public

Output:
================

Error Output:
================
/Users/jialinzhang/code/lavuetify-blog/storage/app/ssr/4957fb2b412b1220dbeb1d7e11e781d9.js:4
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}r.m=e,r.c=t,r.d=function(e,t,n)
.
.
.
n=r("bUC5"),a=r("kPwN");r.n(a)()(n.default,(function(e,t){if(e)throw new Error(e);dispatch(t)}))},yLpj:function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r}});

Error: TypeError: Cannot read property 'render' of undefined
    at /Users/jialinzhang/code/lavuetify-blog/storage/app/ssr/4957fb2b412b1220dbeb1d7e11e781d9.js:4:252658
    at /Users/jialinzhang/code/lavuetify-blog/storage/app/ssr/4957fb2b412b1220dbeb1d7e11e781d9.js:4:252402
    at Module.qLbf (/Users/jialinzhang/code/lavuetify-blog/storage/app/ssr/4957fb2b412b1220dbeb1d7e11e781d9.js:4:252621)
    at r (/Users/jialinzhang/code/lavuetify-blog/storage/app/ssr/4957fb2b412b1220dbeb1d7e11e781d9.js:4:110)
    at Object.2 (/Users/jialinzhang/code/lavuetify-blog/storage/app/ssr/4957fb2b412b1220dbeb1d7e11e781d9.js:4:949)
    at r (/Users/jialinzhang/code/lavuetify-blog/storage/app/ssr/4957fb2b412b1220dbeb1d7e11e781d9.js:4:110)
    at /Users/jialinzhang/code/lavuetify-blog/storage/app/ssr/4957fb2b412b1220dbeb1d7e11e781d9.js:4:910
    at Object.<anonymous> (/Users/jialinzhang/code/lavuetify-blog/storage/app/ssr/4957fb2b412b1220dbeb1d7e11e781d9.js:4:919)
    at Module._compile (internal/modules/cjs/loader.js:1185:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
 (View: /Users/jialinzhang/code/lavuetify-blog/resources/views/ssr.blade.php) in file /Users/jialinzhang/code/lavuetify-blog/vendor/symfony/process/Process.php on line 252

composer & package "laravel/framework": "^7.0", "spatie/laravel-server-side-rendering": "^1.4" "vue-server-renderer": "^2.6.11", "vuer": "^2.6.11",

// ssr.blade.php
<!doctype html>
<html lang="{{ app()->getLocale() }}">
  <head>
    <title>My server side rendered app</title>
      <!-- Styles -->
      <link href="{{ mix('css/app.css', 'assets') }}" rel="stylesheet">
      <script defer src="{{ mix('js/app-client.js', 'assets') }}"></script>
  </head>
  <body>
  {!! ssr('assets/js/app-server.js')->render() !!}
  </body>
</html>
// app.js
import Vue from "vue";

export default () =>
  new Vue({
    template: `
    <div>Hello, world!</div>
  `
  });
// app-server.js
import app from './app';
import renderVueComponentToString from 'vue-server-renderer/basic';

renderVueComponentToString(app, (err, html) => {
    if (err) {
        throw new Error(err);
    }
    dispatch(html);
});
// app-client.js
import createApp from "./app";
const app = createApp();
app.$mount("#app");
zjalen commented 4 years ago

By the way, spa mode <div id='app'></div> run successfully.

clonesia commented 4 years ago

I've same issue too.. any solution?

zjalen commented 4 years ago

@clonesia I've resolved it.I created a file named App.vue.Then import it to app.js.

// App.vue
<template>
    <h1>Hello World</h1>
</template>
// app.js
import Vue from 'vue'
import App from './App.vue'
export default new Vue({
  render: h => h(App)
})

You can have a try. Sorry to bother you @NSpehler . I think you should update the document.I'm afraid there is not only one mistake. :)

spatie-bot commented 4 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.