作りたいものがありすぎる

40歳を過ぎてプログラミングを始めた人の顛末とこれからなど

NativePHP alphaバージョンをwindows10環境で動かしてみた

NativePHP | Baking Delicious Native Apps

なんとLaravelでデスクトップアプリの開発が出来るという変態アプリがでてきたので稼働確認までをやってみました。デスクトップアプリは作ってみたい気持ちがあったのですが、Web系ばかりの私にはハードルが高くて尻込みしてましたが、Laravelでやれるなら!と思ってひとまずいじってみました。

環境

  • windows10 64bit
  • PHP version 8.1.8
  • composer version 2.3.9
  • nodejs 18.17.1

以下の手順に従いインストール Installation - NativePHP

まずLaravelをインストールする

$ composer create-project laravel/laravel example-app

作成したLaravelのプロジェクトフォルダに移動

$ cd example-app

そして nativephpのパッケージをLaravelにcomposerで追加する

$ composer require nativephp/electron

php artisanコマンドを叩いて native PHP関連のコマンドが追加されていればOK!

$ php artisan
Laravel Framework 10.20.0

...省略...

native
  native:build
  native:install          Install all of the NativePHP resources
  native:migrate          Run the database migrations in the NativePHP development environment
  native:minify
  native:publish
  native:queue
  native:serve

...省略...

サーバーの起動を行う

$ php artisan native:serve

  Starting NativePHP dev server… 

 Fetching latest dependencies…

 Installing NPM dependencies (This may take a while)...

 Installing NPM dependencies using the npm package manager...

 Fetching latest dependencies…


 Starting NativePHP app

 Running the dev script with npm...

 Fetching latest dependencies…

しかしエラーとなる

[Window Title]
Error

[Main Instruction]
A JavaScript error occurred in the main process

[Content]
Uncaught Exception:
Error: spawn C:\Users\sakam\study\nativePHP-demo2\vendor\nativephp\electron\resources\js\resources\php\php ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

[OK]

(と、同時にアプリのアクセスを許可する旨のダイアログ窓がでるのでこれは許可しておく)

エラーダイアログで検索する(ダイアログ選択でCtrl + Cでメッセ―ジをコピーできる)と、以下のページがヒット。どうもバグがあるらしい

[Bug]: A Javascript Error Occured In The Main Process. · Issue #105 · NativePHP/laravel · GitHub

これらのコメントに従いリンク先のファイルの内容を書き換える。 [Bug]: A Javascript Error Occured In The Main Process. · Issue #105 · NativePHP/laravel · GitHub

To fix this visit => vendor\nativephp\electron\resources\js\electron-builder.js

https://paste.laravel.io/6c7100ed-fc2f-4d27-ad06-060d70e793fd

Replace this file

now run below command in sequence :-

=> php artisan native:install => php artisan native:build win (you will get >error a popup click ok and let complete process). => php artisan native:serve

vendorの中の以下のファイルを

vendor\nativephp\electron\resources\js\electron-builder.js

以下のリンク先のソースに書き換える Pastebin | Laravel.io

以下のコマンドを再度実行

php artisan native:install
# メッセージが出ているがGitbashだと表示されなかった、enterキーを2回程押して先に進める

php artisan native:build win
# 完了時に構文エラーのダイアログが出るがひとまず無視する

# サーバー起動
php artisan native:serve

これで開発用のウィンドウが立ち上がる

まだ具体的いじってはいませんが、alpha版がなんか立ち上がらないなーという方のご参考になれば幸い。