NativePHP / laravel

Laravel wrapper for the NativePHP framework
https://nativephp.com
MIT License
3.17k stars 164 forks source link

[Bug]: 0.3.1 still fails to build on mac-x86 #128

Closed wattsie closed 6 months ago

wattsie commented 1 year ago

What happened?

Hi all, Sorry to bug, but on creating a fresh laravel install, including latest 0.3.1 and trying to build on x86 mac, it still fails.

Install appears to work no errors now.

However...

Wondering where the --x64 flag is coming from... shouldnt it be --x86 ??

The directory /Users/me/tmp/test1/vendor/nativephp/php-bin/bin/mac/x64 does NOT exist. However the /Users/me/tmp/test1/vendor/nativephp/php-bin/bin/mac/x86 is available...


~/tmp/test1 ❯ php artisan native:build mac-x86
Build NativePHP app…

changed 13 packages, and audited 574 packages in 39s

81 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Package operations: 0 installs, 0 updates, 37 removals
  - Removing theseer/tokenizer (1.2.1)
  - Removing symfony/yaml (v6.3.0)
  - Removing spatie/laravel-ignition (2.2.0)
  - Removing spatie/ignition (1.9.0)
  - Removing spatie/flare-client-php (1.4.1)
  - Removing spatie/backtrace (1.5.3)
  - Removing sebastian/version (4.0.1)
  - Removing sebastian/type (4.0.0)
  - Removing sebastian/recursion-context (5.0.0)
  - Removing sebastian/object-reflector (3.0.0)
  - Removing sebastian/object-enumerator (5.0.0)
  - Removing sebastian/lines-of-code (2.0.0)
  - Removing sebastian/global-state (6.0.1)
  - Removing sebastian/exporter (5.0.0)
  - Removing sebastian/environment (6.0.1)
  - Removing sebastian/diff (5.0.3)
  - Removing sebastian/complexity (3.0.0)
  - Removing sebastian/comparator (5.0.0)
  - Removing sebastian/code-unit-reverse-lookup (3.0.0)
  - Removing sebastian/code-unit (2.0.0)
  - Removing sebastian/cli-parser (2.0.0)
  - Removing phpunit/phpunit (10.2.6)
  - Removing phpunit/php-timer (6.0.0)
  - Removing phpunit/php-text-template (3.0.0)
  - Removing phpunit/php-invoker (4.0.0)
  - Removing phpunit/php-file-iterator (4.0.2)
  - Removing phpunit/php-code-coverage (10.1.3)
  - Removing phar-io/version (3.2.1)
  - Removing phar-io/manifest (2.0.3)
  - Removing nunomaduro/collision (v7.7.0)
  - Removing myclabs/deep-copy (1.11.1)
  - Removing mockery/mockery (1.6.4)
  - Removing laravel/sail (v1.23.1)
  - Removing laravel/pint (v1.10.5)
  - Removing hamcrest/hamcrest-php (v2.0.1)
  - Removing filp/whoops (2.15.3)
  - Removing fakerphp/faker (v1.23.0)
  0/27 [>---------------------------]   0%
 10/27 [==========>-----------------]  37%
 19/27 [===================>--------]  70%
 26/27 [==========================>-]  96%
 27/27 [============================] 100%
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   INFO  Discovering packages.

  laravel/sanctum ....................................................... DONE
  laravel/tinker ........................................................ DONE
  nativephp/electron .................................................... DONE
  nativephp/laravel ..................................................... DONE
  nesbot/carbon ......................................................... DONE
  nunomaduro/termwind ................................................... DONE

53 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

> NativePHP@1.0.0 build:mac-x86
> cross-env node php.js --x64 && cross-env npm run build && cross-env electron-builder -p never --mac --config --x64

Binary Source:  /Users/me/tmp/test1/vendor/nativephp/php-bin/bin/mac/x64
Binary Filename:  php
Copying PHP file(s) from /Users/me/tmp/test1/vendor/nativephp/php-bin/bin/mac/x64 to /Users/me/tmp/test1/vendor/nativephp/electron/resources/js/resources/php
Error copying PHP binary Error: ENOENT: no such file or directory, stat '/Users/me/tmp/test1/vendor/nativephp/php-bin/bin/mac/x64'
    at Object.statSync (node:fs:1706:3)
    at Object.statSync (/Users/me/tmp/test1/vendor/nativephp/electron/resources/js/node_modules/graceful-fs/polyfills.js:318:34)
    at statSync (/Users/me/tmp/test1/vendor/nativephp/electron/resources/js/node_modules/fs-extra/lib/util/stat.js:10:52)
    at getStatsSync (/Users/me/tmp/test1/vendor/nativephp/electron/resources/js/node_modules/fs-extra/lib/util/stat.js:24:19)
    at Object.checkPathsSync (/Users/me/tmp/test1/vendor/nativephp/electron/resources/js/node_modules/fs-extra/lib/util/stat.js:49:33)
    at copySync (/Users/me/tmp/test1/vendor/nativephp/electron/resources/js/node_modules/fs-extra/lib/copy-sync/copy-sync.js:24:38)
    at Object.<anonymous> (/Users/me/tmp/test1/vendor/nativephp/electron/resources/js/php.js:37:9)
    at Module._compile (node:internal/modules/cjs/loader:1233:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32) {
  errno: -2,
  syscall: 'stat',
  code: 'ENOENT',
  path: '/Users/me/tmp/test1/vendor/nativephp/php-bin/bin/mac/x64'
}
Copied certificate file to /Users/me/tmp/test1/vendor/nativephp/electron/resources/js/resources/cacert.pem

> NativePHP@1.0.0 build
> electron-vite build

vite v4.4.7 building for production...
✓ 3 modules transformed.
✓ built in 50ms
Could not resolve "../../resources/php/php?asset&asarUnpack" from "src/main/index.js"
file: /Users/me/tmp/test1/vendor/nativephp/electron/resources/js/src/main/index.js
error during build:
RollupError: Could not resolve "../../resources/php/php?asset&asarUnpack" from "src/main/index.js"
    at error (file:///Users/me/tmp/test1/vendor/nativephp/electron/resources/js/node_modules/rollup/dist/es/shared/node-entry.js:2245:30)
    at ModuleLoader.handleInvalidResolvedId (file:///Users/me/tmp/test1/vendor/nativephp/electron/resources/js/node_modules/rollup/dist/es/shared/node-entry.js:24654:24)
    at file:///Users/me/tmp/test1/vendor/nativephp/electron/resources/js/node_modules/rollup/dist/es/shared/node-entry.js:24616:26

~/tmp/test1 ❯                                                                                                                                                                                                                              took  46s

How to reproduce the bug

In a "tmp" directory hanging of home directory (be be sure there are no permission issues)

# New Laravel Skeleton
laravel new test1

cd test1

# Add latest NativePHP
composer require nativephp/electron:0.3.1

# install deps
php artisan native:install

# test start the app
php artisan native:serve

# build the app
php artisan native:build mac-x86

Package Version

0.3.1

PHP Version

8.1

Laravel Version

10.16.1

Which operating systems does with happen with?

macOS

Notes

Please note, Mac Intel x86 based

wattsie commented 1 year ago

BTW: I thought I found a workaround...

If I copy vendor/nativephp/php-bin/bin/mac/x86 to vendor/nativephp/php-bin/bin/mac/x64 and try build it works.

But when I launch the app, the window shows, but I get a "500 | SERVER ERROR"

PS: in config/nativephp.php I have set NATIVEPHP_UPDATER_ENABLED to false (tried in .env still doesnt disable)

~/tmp/test2 ❯ ./dist/mac/Laravel.app/Contents/MacOS/Laravel                                                                                                                                                                                     ↵ INT
API server started on port 4000
Starting PHP server... /Users/me/tmp/test2/dist/mac/Laravel.app/Contents/Resources/app.asar.unpacked/resources/php/php artisan serve /Users/me/tmp/test2/dist/mac/Laravel.app/Contents/Resources/app.asar.unpacked/resources/app/
Making sure app folders are available
PHP Server started on port:  8100
(node:69696) electron: NSVisualEffectMaterialAppearanceBased has been deprecated and removed as of macOS 10.15.
(Use `Laravel --trace-warnings ...` to show where the warning was created)
Checking for update
Error: Error: net::ERR_NAME_NOT_RESOLVED
    at SimpleURLLoaderWrapper.<anonymous> (node:electron/js2c/browser_init:2:49935)
    at SimpleURLLoaderWrapper.emit (node:events:513:28)
(node:69696) UnhandledPromiseRejectionWarning: Error: net::ERR_NAME_NOT_RESOLVED
    at SimpleURLLoaderWrapper.<anonymous> (node:electron/js2c/browser_init:2:49935)
    at SimpleURLLoaderWrapper.emit (node:events:513:28)
(node:69696) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
phuclh commented 1 year ago

I got the same issue on M1 (arm64)

vitorleonel commented 1 year ago

I've the same error here and I opened a PR in order to fix it.

https://github.com/NativePHP/php-bin/pull/7

vitorleonel commented 1 year ago

@mpociot As far as I understood, when we compile the php for Mac OS when it's not arm, the binary is the same for the x86 and x64.

Could I come up with a PR for this repository and then we can identify if it isn't arm, we search for a folder "x64_x86", so we don't need to have a duplicated binary in the php-bin repository.

What do you think?

Jonnx commented 1 year ago

+1

simonhamp commented 6 months ago

The logic for determining which Mac platform to build for has been improved in recent weeks.

Please run composer update to get the latest version and try again.