spatie / server-side-rendering

Server side rendering JavaScript in a PHP application
https://sebastiandedeyne.com/posts/2018/server-side-rendering-javascript-from-php
MIT License
602 stars 34 forks source link

Issue with access to global process variable when using Webpack #24

Closed foxik0169 closed 4 years ago

foxik0169 commented 5 years ago

Hello,

I've stumbled upon an issue with when using Node engine with server-side bundle generated by Webpack 4. In the javascript generation process in the Renderer class, there's following line added to the file:

var process = process || { env: {} };

In my case, the process global resolves to undefined, which causes my script to malfunction - axios won't recognize Node environment. Axios can be thus used to reproduce this issue as it uses this condition to determine Node env typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]'.

To fix this, I've replaced the global with require('process') which solved the issue for my instance.

I wanted to ask if this is by design and/or this is some issue with the webpack bundle or it is, indeed, a bug.

Node versions: 12.4.0 / 6.16.0 - both same result Webpack version: 4.34.0 - target set to 'node', transpilation via babel

Thanks for feedback. Daniel

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.