Closed ysufmv closed 2 weeks ago
I assume that this is somehow related to the way PHP resolves the node
binary (and possibly other environment variables needed for executing this).
Could you try and re-run the same code in Herd but pass an absolute path to "node"?
Platform
Windows
Operating system version
Windows 11 Pro (23H2 22631.3880)
System architecture
Windows
Herd Version
1.8.0 (Pro)
PHP Version
No response
Bug description
In Laravel Herd for Windows, attempting to run exec( ) on a Node.js script that imports Puppeteer fails with an EISDIR error. Simple scripts work. And to test for an alternative I tried importing Playwright which works fine and the script executes succesfully.
The same code to import Puppeteer works correctly when executed in a XAMPP server instead of Laravel Herd, and the script succesfully executes.
The issue cropped up when I was doing some testing on my main site. To make sure there is no intereference from any other packages / scripts, I added a new Laravel instance called nodetest using Herd and chose default configurations.
The reason why I am trying to access Puppeteer on the back-end, via Laravel exec(), is because its a business logic that needs to be hidden from the front-end users, and, right now it is the only way possible I know of that can achieve the same results on my actual production server. That is not the goal of raising this issue.
The outcome from raising this issue would be to identify and resolve the reason why it fails to work on Laravel Herd while the same code works on a Xampp server. I am assuming that it is not specific to Puppeteer and other packages may also fail to import.
My Laravel Herd Active Services
The php & node version![image](https://github.com/beyondcode/herd-community/assets/78437612/374fd94e-49ac-4003-bc03-b7659dfaf198)
Sites:![image](https://github.com/beyondcode/herd-community/assets/78437612/78285bdc-4034-4ffa-8773-df263790bafa)
Further background: I have the following installed on Windows, prior to installing Laravel Herd: Composer Xampp for Windows PHP 8.2.12 (All services stopped for the test) Node v21.5.0 (Might be interferring - but I don't know if its relevant) npm v10.2.4 pnpm v9.0.6
Also tested on a Hyper-V Virtual Machine with a fresh Windows installation via ISO image.
Steps to reproduce
Assuming that you have Laravel Herd (1.8.0) installed. If you have Xampp or any other similar services installed, you can stop all of its services and close it.
Click to Enable HTTPS and allow the creation and addition of certificates by allowing Windows PowerShell to run. I don't think this is relevant but since we are retracing my steps to reproduce the error.
Open Terminal and install Puppeteer:
pnpm i puppeteer
After installation is complete. Open your Project on your code editor.
Go to
routes/web.php
and change the route for: " / " (welcome) route to the following:public
folder and create a file named:checkPuppeteer.js
Add the following code:
As seen:
To check if it works normally, you can run the
checkPuppeteer.js
on the terminal as below: 'cd' into the 'public' folder and type:node checkPuppeteer.js
It should execute successfully, as above.
exec( )
we can replace the code incheckPuppeteer.js
to something that doesn't include the puppeteer import, like:It should execute succesfully:
For good measure I wanted to see if an alternative package would work, so I installed Playwright
Playwright
by installing it from the terminal:Change your
checkPuppeteer.js
code to below to check with Playwright:Open the website on your browser. You would see that it takes a few more seconds to load because in the background the script is succesfully executing. Afterwards, you should see the dump on the screen showing it is succesful:![image](https://github.com/beyondcode/herd-community/assets/78437612/a7cc76cb-49a6-492f-9a97-cb403e9de2ac)
All this works just fine on Xampp server, which was what I was using till recently. But after exploring Laravel Herd, I immediately wanted to make it my go-to development server. I subscribed to Laravel Herd Pro and was on my way to get everything sorted when this popped up, and it's been nagging me.
It may not be a major issue or something to do with my configurations. (I've tested the same on a frest Hyper-V Virtual Machine (Windows 11 with Windows ISO image)
Steps Taken
Setup Hyper-V Machine and install Windows 11
Download latest version of Laravel Herd and install it.
php, laravel, composer is installed. node is also installed. Pressing the terminal opens up Windows Powershell but node is not available there. So I encountered errors when I tried to replicate above steps because node was not available in Powershell and when Laravel was calling node via exec(), it was opening Powershell. I assumed it was due to not being added to PATH or Powershell. So I proceeded to download nodejs v22.4.1 prebuilt installer for Windows and installed it with Additional binaries option checked on. After installation, it was still not available on Powershell so I added it manually by going to Settings > System > About > Advanced system settings > Environment Variables > PATH > New > Type in:
C:\Program Files\nodejs\
and click OK. Then open Windows Powershell with administrator rights and Type:[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\nodejs\", [EnvironmentVariableTarget]::Machine)
It should add node to Powershell. Restart Windows to ensure all settings are ok.Afterwards, repeat the instructions from the top of this section to replicate the same error. (instead of pnpm I used npm since I would need to install pnpm as well)
Why I am posting this: I love the simplicity of Laravel Herd and want to work with it in the future. This may be an edge case. But it forces me to go back and use Xampp or change the packages I currently use.
I may have missed some very simple solutions that could circumvent this error. So I'm all ears.
Relevant log output