5

I am attempting to implement SSR with VueJS, VueRouter in Laravel using V8Js, and I keep coming up with this error:

V8JsScriptException
V8Js::compileString():1812: ReferenceError: document is not defined

import App from './app'
import Vue from "vue";
import router from "./router";

let app = new Vue(App);

Vue.config.productionTip = false;
// @ts-ignore
export default new Promise((resolve, reject) => {
  // @ts-ignore
  router.push(url);
  router.onReady(() => {
    const matchedComponents = router.getMatchedComponents();
    if (!matchedComponents.length) {
      return reject({
        code: 404
      });
    }
    resolve(app);
  }, reject);
}).then(app => {
  // @ts-ignore
  renderVueComponentToString(app, (err, res) => {
    // @ts-ignore
    print(res);
  });
}).catch((err) => {
  // @ts-ignore
  print(err);
});
      ...

      $js =
            <<<EOT
            var process = { env: { VUE_ENV: "server", NODE_ENV: "production" } }; 
            this.global = { process: process }; 
            var url = "$path";
EOT;
        $v8 = new \V8Js();

        $v8->executeString($js);
        $v8->executeString($renderer_source);

        $v8->executeString($app_source);
        $markup = ob_get_clean();
        return $markup;

       ...

In SSR there are no window nor document, I know, but I cannot tell where's my error. If there's anymore details needed I can provide, thank you.

Eddy Ekofo
  • 541
  • 6
  • 13

0 Answers0