8000 [Bug]: TypeError: Cannot read properties of undefined (reading 'setIcon') · Issue #22 · NativePHP/laravel · GitHub
[go: up one dir, main page]

Skip to content

[Bug]: TypeError: Cannot read properties of undefined (reading 'setIcon') #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fanorama opened this issue Jul 21, 2023 · 11 comments
Closed
Labels
bug Something isn't working

Comments

@fanorama
Copy link
fanorama commented Jul 21, 2023

What happened?

I getting this error when run my laravel app with nativephp

[7075:0721/100333.390724:ERROR:object_proxy.cc(590)] Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/portal/desktop: org.freedesktop.DBus.Error.InvalidArgs: No such interface “org.freedesktop.portal.FileChooser”
[7075:0721/100333.390847:ERROR:select_file_dialog_linux_portal.cc(274)] Failed to read portal version property

(node:7075) UnhandledPromiseRejectionWarning: TypeError: Cannot read properties of undefined (reading 'setIcon')
at NativePHP. (/home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/node_modules/nativephp-electron/dist/index.js:81:26)
at Generator.next ()
at /home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/node_modules/nativephp-electron/dist/index.js:8:71
at new Promise ()
at __awaiter (/home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/node_modules/nativephp-electron/dist/index.js:4:12)
at /home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/node_modules/nativephp-electron/dist/index.js:78:36
(Use electron --trace-warnings ... to show where the warning was created)

(node:7075) 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: 2)

How to reproduce the bug

When i run native:serve command it give me this error

Package Version

0.1.0

PHP Version

8.1

Laravel Version

10.2

Which operating systems does with happen with?

Linux

Notes

No response

@fanorama fanorama added the bug Something isn't working label Jul 21, 2023
@elsayed85
Copy link

try to navigate to the code and disable the lines
vendor/nativephp/electron/resources/js/node_modules/nativephp-electron/dist/index.js
// if (process.env.NODE_ENV === 'development') {
// app.dock.setIcon(state_1.default.icon);
// }

        just for debug 

@fanorama
Copy link
Author

try to navigate to the code and disable the lines vendor/nativephp/electron/resources/js/node_modules/nativephp-electron/dist/index.js // if (process.env.NODE_ENV === 'development') { // app.dock.setIcon(state_1.default.icon); // }

        just for debug 

The error for setIcon is fixed and the app success to run until database migration, the first error still exist and get new issue the binary cant executed.

start electron app...

[10137:0721/101839.138587:ERROR:object_proxy.cc(590)] Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/portal/desktop: org.freedesktop.DBus.Error.InvalidArgs: No such interface “org.freedesktop.portal.FileChooser”
[10137:0721/101839.138652:ERROR:select_file_dialog_linux_portal.cc(274)] Failed to read portal version property

Error: Command failed: /home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/resources/php artisan native:config
/home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/resources/php: /home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/resources/php: cannot execute binary file

at ChildProcess.exithandler (node:child_process:430:12)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1091:16)
at Socket.<anonymous> (node:internal/child_process:449:11)
at Socket.emit (node:events:513:28)
at Pipe.<anonymous> (node:net:322:12) {

code: 126,
killed: false,
signal: null,
cmd: '/home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/resources/php artisan native:config',
stdout: '',
stderr: '/home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/resources/php: /home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/resources/php: cannot execute binary file\n'
}

API server started on port 4000

Starting PHP server... /home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/resources/php artisan serve /home/septiandev/Development/my-laravel-boilerplate

Making sure app folders are available

Migrating database...

/home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/resources/php: /home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/resources/php: cannot execute binary file

@fanorama fanorama changed the title [Bug]: UnhandledPromiseRejectionWarning: TypeError: Cannot read properties of undefined (reading 'setIcon') [Bug]: TypeError: Cannot read properties of undefined (reading 'setIcon') Jul 21, 2023
@mattsches
Copy link

Migrating database...

/home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/resources/php: /home/septiandev/Development/my-laravel-boilerplate/vendor/nativephp/electron/resources/js/resources/php: cannot execute binary file`

This is probably because the PHP binary used here is the MacOS binary. NativePHP does not support Linux yet (I've even read that somewhere but cannot find the source anymore; it's not in the docs).

$ file vendor/nativephp/electron/resources/js/resources/php 
vendor/nativephp/electron/resources/js/resources/php: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE>

@tochiv
Copy link
tochiv commented Jul 21, 2023

Fixed, but got new issue

Error: Command failed: /home/tochiv/PhpstormProjects/testNative/vendor/nativephp/electron/resources/js/resources/php artisan native:config
/home/tochiv/PhpstormProjects/testNative/vendor/nativephp/electron/resources/js/resources/php: 1: ����
��: not found
/home/tochiv/PhpstormProjects/testNative/vendor/nativephp/electron/resources/js/resources/php: 2: Syntax error: word unexpected (expecting ")")

at ChildProcess.exithandler (node:child_process:430:12)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1091:16)
at Socket.<anonymous> (node:internal/child_process:449:11)
at Socket.emit (node:events:513:28)
at Pipe.<anonymous> (node:net:322:12) {

code: 2,
killed: false,
signal: null,
cmd: '/home/tochiv/PhpstormProjects/testNative/vendor/nativephp/electron/resources/js/resources/php artisan native:config',
stdout: '',
stderr: '/home/tochiv/PhpstormProjects/testNative/vendor/nativephp/electron/resources/js/resources/php: 1: ����\f\x01\x02\x16�\x07�: not found\n' +
'/home/tochiv/PhpstormProjects/testNative/vendor/nativephp/electron/resources/js/resources/php: 2: Syntax error: word unexpected (expecting ")")\n'
}

API server started on port 4000
Starting PHP server... /home/tochiv/PhpstormProjects/testNative/vendor/nativephp/electron/resources/js/resources/php artisan serve /home/tochiv/PhpstormProjects/testNative
Making sure app folders are available

Migrating database...

/home/tochiv/PhpstormProjects/testNative/vendor/nativephp/electron/resources/js/resources/php: 1: ����
��: not found
/home/tochiv/PhpstormProjects/testNative/vendor/nativephp/electron/resources/js/resources/php: 2: Syntax error: word unexpected (expecting ")")

libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[14070:0721/121046.768100:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)

Linux

@antonioanerao
Copy link
antonioanerao commented Jul 21, 2023

I managed to use the project in Ubuntu

After you run php artisan native:install, say no when it ask you to run the server. Then, copy you php file from /usr/bin/php to nativephp/vendor/nativephp/php-bin/bin/mac/x86.

After that when you run php artisan native:run it will use your php library instead of the mac php library version

@patoui
Copy link
patoui commented Jul 21, 2023

@antonioanerao thank you for that information! I've added a few more details below.

Steps:

  • php artisan native:install when prompted to start the development server select "no"
  • run the commands below from the project root
sed -i 's/app.dock.setIcon(state_1.default.icon);/\/\/app.dock.setIcon(state_1.default.icon);/g' vendor/nativephp/electron/resources/js/node_modules/nativephp-electron/dist/index.js
cp -L /usr/bin/php vendor/nativephp/php-bin/bin/mac/x86/php
  • run php artisan native:serve

Here's a gist with a script
https://gist.github.com/patoui/494689db112b11d52a63be34dc538511

@horaciod
Copy link

works for linux mint 21 , thanks

@simonhamp
Copy link
Member

You probably don't want to copy the executable built on your platform as it's most likely dynamically linked. This will likely only work on your machine

This means it won't be distributable to other machines when you come to package up your app for distribution.

You need a static build of PHP specifically for Linux.

First-party Linux support is coming very soon (we've already built the binaries, we just need to package 8000 them up)

@bpjuli22
Copy link

Bug fixed for demo for Linux OS:
first of all copy the php file from linux:
cp -L /usr/bin/php yourAppDirectory/vendor/nativephp/php-bin/bin/mac/x86/php

second comment the setIcon issue:
path: yourAppDirectory/vendor/nativephp/electron/resources/js/node_modules/@nativephp/electron-plugin/dist/index.js
comment: line 79 or find setIcon and comment it.

finally,
run: php artisan native:serve

@antonioanerao
Copy link
antonioanerao commented Jul 23, 2023

You probably don't want to copy the executable built on your platform as it's most likely dynamically linked. This will likely only work on your machine

This means it won't be distributable to other machines when you come to package up your app for distribution.

You need a static build of PHP specifically for Linux.

First-party Linux support is coming very soon (we've already built the binaries, we just need to package them up)

That's just a way to hack around while we wait for the linux support :D We want to play with NativePHP. I`m already making some nice stuff just for fun.

@mpociot
Copy link
Member
mpociot commented Jul 25, 2023

The setIcon code now only gets executed on macOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants
0