-
-
Notifications
You must be signed in to change notification settings - Fork 13
Description
What were you trying to do?
🐛 Bug Report
Description
Windows builds created with php artisan native:build win fail to launch. The built .exe file runs as a background process but never displays a window. Investigation reveals a critical path construction bug in php.js causing ENOENT errors.
Environment
- NativePHP Version: v2.0.2
- Laravel Version: 12.x
- PHP Version: 8.3
- Node Version: 22.21.1
- Electron Version: 38.3.0
- Operating System: Windows 11 (affects all Windows versions)
- Install Method:
composer require nativephp/desktop
Steps to Reproduce
-
Create a new Laravel project with NativePHP:
composer create-project laravel/laravel notelab cd notelab composer require nativephp/desktop php artisan native:install -
Create basic NativeAppServiceProvider:
public function boot(): void { Window::open() ->title('Test App') ->width(800) ->height(600); }
-
Build for Windows:
php artisan native:build win
-
Run the built executable:
.\nativephp\electron\dist\win-unpacked\YourApp.exe
-
Observe: Process starts but no window appears
Expected Behavior
- Application should launch
- Main window should appear
- App should be usable
Actual Behavior
- Application starts as background process
- No window appears
- Task Manager shows process running
- No UI displayed
- Application hangs indefinitely
Error Details
When running php artisan native:run -vvv, the following error appears:
Error: ENOENT: no such file or directory
errno: -4058
code: 'ENOENT'
path: 'C:\\Users\\user\\project\\C:\\Users\\user\\project\\vendor\\nativephp\\php-bin\\binbin\\win\\x64\\php-8.4.zip'
Key issue: Notice the path is doubled - it contains the base path twice, making it invalid.
Root Cause Analysis
File: nativephp/electron/php.js (line ~63)
Issue: Path construction doesn't check if phpBinaryPath is already absolute
// BROKEN CODE:
const phpBinaryPath = process.env.NATIVEPHP_PHP_BINARY_PATH;
// This is ALREADY absolute: "C:\\Users\\user\\project\\vendor\\nativephp\\php-bin\\bin"
const binarySrcDir = join(phpBinaryPath, platform.os, platform.arch, phpVersionZip);
// But somewhere upstream, this gets joined with base_path() AGAIN
// Result: "C:\\project\\C:\\project\\vendor\\..." (INVALID!)Proposed Fix
Add logic to detect absolute vs relative paths:
// FIX: Check if phpBinaryPath is absolute or relative
const isAbsolutePath = phpBinaryPath && (
phpBinaryPath.includes(':') || // Windows: C:\...
phpBinaryPath.startsWith('\\\\') || // Windows UNC: \\server\...
phpBinaryPath.startsWith('/') // Unix: /usr/...
);
let binarySrcDir;
if (isAbsolutePath) {
// Already absolute - use directly
binarySrcDir = join(phpBinaryPath, platform.os, platform.arch, phpVersionZip);
} else {
// Relative path - resolve from APP_PATH or current directory
const basePath = process.env.APP_PATH || process.cwd();
binarySrcDir = join(basePath, phpBinaryPath, platform.os, platform.arch, phpVersionZip);
}Workarounds Attempted
- ❌ Setting
NATIVEPHP_PHP_BINARY_PATHin.env- still fails - ❌ Using relative paths - gets converted to absolute
- ❌ Clean build/reinstall - same issue
- ✅ Development mode works:
composer native:devfunctions normally
Impact
- Severity: Critical
- Scope: All Windows users
- Frequency: 100% reproduction rate
- Workaround: None for production builds (dev mode works)
Additional Context
This issue prevents ANY Windows user from creating distributable NativePHP applications. The bug has existed since at least v2.0.0 and affects the current stable version (v2.0.2).
Related Issues:
- Similar to ENOENT errors reported in various issues
- Blocks Windows deployment entirely
- Development mode unaffected (uses different path resolution)
Checklist
- I have searched for similar issues
- I have provided all required environment information
- I have included reproduction steps
- I have identified the root cause
- I can provide a PR with fix if needed
Screenshots/Logs
Process in Task Manager:
Image Name: YourApp.exe
PID: 12345
Status: Running
Type: Background process
Console Error (from electron dev tools):
UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory
at Object.open (node:fs:605:3)
at php.js:82Proposed PR
I have a working fix tested locally. Would you like me to submit a PR?
The fix:
- ✅ Handles absolute Windows paths (C:...)
- ✅ Handles UNC paths (\server...)
- ✅ Handles Unix paths (/usr/...)
- ✅ Backwards compatible
- ✅ Tested on Windows 11
- ✅ No breaking changes
This bug is blocking Windows deployment for all users. Priority: HIGH
What happened?
Windows builds created with php artisan native:build win fail to launch. The built .exe file runs as a background process but never displays a window. Investigation reveals a critical path construction bug in php.js causing ENOENT errors.
How to reproduce the bug
Windows builds created with php artisan native:build win fail to launch. The built .exe file runs as a background process but never displays a window. Investigation reveals a critical path construction bug in php.js causing ENOENT errors.
Debug Output
Windows builds created with php artisan native:build win fail to launch. The built .exe file runs as a background process but never displays a window. Investigation reveals a critical path construction bug in php.js causing ENOENT errors.
Which operating systems have you seen this occur on?
No response
Notes
No response