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
how did you solve issue? I also have this section of code
@SeanConnell93 Hmm I didn’t use
yarncommand to reproduce the repo. Just those 3 steps:And yeah that’s right, the repo was able to do
ssrnicely. There are several problems to be addressed:It will throw an error because of either
style-loadernot optimized for isomorphic app. I still have no idea to resolve this.window&documentcode in your components or any js files (I’m pretty sure you already know, this is the main reason why it prints outwindowordocumentis 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
windowordocumentwill 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=nodeAPP_ENV=productionhope this - https://youtu.be/uO42Kpa4pvI will help