laravel-server-side-rendering: error laravel ssr using node

The command “/c/Program Files/nodejs/node C:\xampp\htdocs\Agrirecruit_Laravel\storage\app/ssr\c244232e15965255150ad76e7d13d123.js” failed. Exit Code: 1(General error) Working directory: C:\xampp\htdocs\Agrirecruit_Laravel\public Output

Note: the c244232e15965255150ad76e7d13d123.js never gets written to the storage/app/ssr folder

I’ve been stuck on the same error as this #13 for the past few days and can’t figure it out. Note: I’m using windows 10

I ran which node to get node path I’ve set the NODE_PATH="/c/Program Files/nodejs/node"

APP_ENV=production

Here’s my files.

package.json

"dependencies": { "vee-validate": "^2.0.9", "vue": "^2.5.7", "vue-head": "^2.0.12", "vue-router": "^3.0.1", "vue-server-renderer": "^2.5.16", "vue-the-mask": "^0.11.1", "vue-wysiwyg": "^1.7.2", "vue2-editor": "^2.5.0", "vuex": "^3.0.1" }

mix

mix.js('resources/assets/js/app-client.js', 'public/js') .js('resources/assets/js/app-server.js', 'public/js') .sass('resources/assets/sass/app.scss', 'public/css') .sourceMaps().version();

Blade

<script type="text/javascript" defer src="{{ mix('js/app-client.js') }}"></script>

<main class="container-fuild" id="app"> {!! ssr("js/app-server.js")->render() !!} </main>

The I didn’t change anything in the ssr.php

return [

'enabled' => env('APP_ENV') === 'production',

'debug' => env('APP_DEBUG', false),

'mix' => true,

'engine' => \Spatie\Ssr\Engines\Node::class,

'node' => [
    'node_path' => env('NODE_PATH', '/usr/local/bin/node'),
    'temp_path' => storage_path('app/ssr'),
],

'context' => [],

'env' => [
    'NODE_ENV' => 'production',
    'VUE_ENV' => 'server',
],

];

Client.js

import app from './app'; app.$mount('#app');

Server.js

import app from './app'; import renderVueComponentToString from 'vue-server-renderer/basic'; renderVueComponentToString(app, (err, res) => { if (err) { throw new Error(err); } dispatch(res); });

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16

Most upvoted comments

I’ve experienced your issue above, so I made a change in config/ssr.php file:

'enabled' => true,
'debug' => true,

Removed all the env checking to make them absolute true solved the problem for me.

Also you definitely should check this example repo provided by spatie.

The only thing I couldn’t get it working that is {!! ssr('js/app-server.js')->fallback('<div id="app"></div>')->render() !!} is always going to the fallback. Means that the ssr('js/app-server.js') alone returns empty string or the ssr engine is failing.

Still stuck to this issue for days. Probably it’s a problem from the webpack or the way I import components.

I notice that there this section of code:

/******/ (function(modules) { // webpackBootstrap
/******/ 	// install a JSONP callback for chunk loading
/******/ 	var parentJsonpFunction = window["webpackJsonp"];
/******/ 	window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules, executeModules) {
/******/ 		// add "moreModules" to the modules object,
/******/ 		// then flag all "chunkIds" as loaded and fire callback
/******/ 		var moduleId, chunkId, i = 0, resolves = [], result;
/******/ 		for(;i < chunkIds.length; i++) {
/******/ 			chunkId = chunkIds[i];
/******/ 			if(installedChunks[chunkId]) {
/******/ 				resolves.push(installedChunks[chunkId][0]);
/******/ 			}
/******/ 			installedChunks[chunkId] = 0;
/******/ 		}
/******/ 		for(moduleId in moreModules) {
/******/ 			if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
/******/ 				modules[moduleId] = moreModules[moduleId];
/******/ 			}
/******/ 		}
/******/ 		if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules, executeModules);
/******/ 		while(resolves.length) {
/******/ 			resolves.shift()();
/******/ 		}
/******/
/******/ 	};

In both app-client.js and app-server.js while when I run in the example repo provided, I couldn’t get that kind of code at the beginning of those 2 files. Not sure if this is related to not being able to render ssr('js/app-server.js') at all.

Any help would be appreciated too.

how did you solve issue? I also have this section of code

@SeanConnell93 Hmm I didn’t use yarn command to reproduce the repo. Just those 3 steps:

1. git clone https://github.com/spatie/laravel-server-side-rendering-examples.git
2. composer install
3. npm install

And yeah that’s right, the repo was able to do ssr nicely. There are several problems to be addressed:

  1. You can’t use inline styling in a .vue component (I’ve tried to reproduce this, see #6 ), like:
<template>
<div class="wrapper">
    <h1>Hello World</h1>
</div>
</template>

<style>
h1 {
    font-family: Helvetica;
}
</style>

It will throw an error because of either style-loader not optimized for isomorphic app. I still have no idea to resolve this.

  1. NEVER PUT window & document code in your components or any js files (I’m pretty sure you already know, this is the main reason why it prints out window or document is not defined).

Seriously I need more guidance to integrate SSR with this package. This package does a good job already, just those 2 points above need solution.

I fixed on my Linux OS like this 👍

NODE_PATH=node APP_ENV=production And the Last : Run npm run production (if use NPM)

And Got Luck 💃

@jonathantyar There won’t be one, SSR takes place in server side not client. Therefore window or document will be undefined.

@devsrv Yeah I was able to get the SSR in action weeks ago, thanks

If you are in a windows system set node path in your environment variable then use NODE_PATH=node APP_ENV=production

hope this - https://youtu.be/uO42Kpa4pvI will help