programing

"V8Js::compileString():1812:ReferenceError:document is not defined" Larabel VueJS & V8Js TypeScript

itsource 2022. 7. 14. 20:59
반응형

"V8Js::compileString():1812:ReferenceError:document is not defined" Larabel VueJS & V8Js TypeScript

VueJs를 사용하여 SSR를 구현하고 V8Js를 사용하여 Larabel에 VueRouter를 구현하려고 하면 다음 오류가 계속 발생합니다.

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;

       ...

SSR에는 창도 문서도 없지만 어디에 오류가 있는지 알 수 없습니다.제가 더 자세한 정보를 드릴 수 있다면 감사합니다.

언급URL : https://stackoverflow.com/questions/52241150/v8jscompilestring1812-referenceerror-document-is-not-defined-laravel-vu

반응형