You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a Cordova project which has been retrieved from source control (eg, no platforms or plugin directory) cordova prepare electron when using a plugin which supports the new electron 3.0 plugin model throws an error trying to write to package.json.
What is expected to happen?
Cordova successfully prepares the electron platform with the cordova-plugin-device plugin.
What does actually happen?
npx cordova prepare electron
npx: installed 495 in 39.075s
Discovered platform "electron". Adding it to the project
Using cordova-fetch for cordova-electron@^3.1.0
Adding electron project...
Creating Cordova project for cordova-electron:
Path: C:\dev\testusecase\myApp\platforms\electron
Name: myApp
Discovered plugin "cordova-plugin-device". Adding it to the project
Installing "cordova-plugin-device" for electron
Error during processing of action! Attempting to revert...
Failed to install 'cordova-plugin-device': Error: Uh oh!
ENOENT: no such file or directory, open 'C:\dev\testusecase\myApp\platforms\electron\www\package.json'
at Object.openSync (fs.js:497:3)
at Object.readFileSync (fs.js:393:35)
at Object.install (C:\dev\testusecase\myApp\node_modules\cordova-electron\lib\handler.js:131:44) at C:\dev\testusecase\myApp\node_modules\cordova-electron\lib\Api.js:212:31
at ActionStack.process (C:\dev\testusecase\myApp\node_modules\cordova-common\src\ActionStack.js:56:25)
at Api.addPlugin (C:\dev\testusecase\myApp\node_modules\cordova-electron\lib\Api.js:132:24)
at handleInstall (C:\Users\m.hipper\AppData\Roaming\npm-cache_npx\32496\node_modules\cordova\node_modules\cordova-lib\src\plugman\install.js:561:10)
at C:\Users\m.hipper\AppData\Roaming\npm-cache_npx\32496\node_modules\cordova\node_modules\cordova-lib\src\plugman\install.js:344:28
at processTicksAndRejections (internal/process/task_queues.js:95:5)
Uh oh!
ENOENT: no such file or directory, open 'C:\dev\testusecase\myApp\platforms\electron\www\package.json'
Error: spawn C:\Windows\system32\cmd.exe ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
Information
I found the issue working on a native file system plugin for electron and was able to reproduce it with cordova-plugin-device since it was upgraded. When you install electron and then add the plugin everything works fine because the package json is already there. In the situation of source control and build servers however it fails because prepare which also installs plugins have a race condition on the package.json file inside electron\www (Different to the root project package.json).
I have a work around which is to add a hook before the plugin is installed to create an empty package.json file {} which the plugin install then populates, followed by the main meta data.
config.xml <hook src="before_plugin_install.js" type="before_plugin_install" />
Bug Report
Problem
In a Cordova project which has been retrieved from source control (eg, no platforms or plugin directory)
cordova prepare electron
when using a plugin which supports the new electron 3.0 plugin model throws an error trying to write to package.json.What is expected to happen?
Cordova successfully prepares the electron platform with the cordova-plugin-device plugin.
What does actually happen?
npx cordova prepare electron
npx: installed 495 in 39.075s
Discovered platform "electron". Adding it to the project
Using cordova-fetch for cordova-electron@^3.1.0
Adding electron project...
Creating Cordova project for cordova-electron:
Path: C:\dev\testusecase\myApp\platforms\electron
Name: myApp
Discovered plugin "cordova-plugin-device". Adding it to the project
Installing "cordova-plugin-device" for electron
Error during processing of action! Attempting to revert...
Failed to install 'cordova-plugin-device': Error: Uh oh!
ENOENT: no such file or directory, open 'C:\dev\testusecase\myApp\platforms\electron\www\package.json'
at Object.openSync (fs.js:497:3)
at Object.readFileSync (fs.js:393:35)
at Object.install (C:\dev\testusecase\myApp\node_modules\cordova-electron\lib\handler.js:131:44) at C:\dev\testusecase\myApp\node_modules\cordova-electron\lib\Api.js:212:31
at ActionStack.process (C:\dev\testusecase\myApp\node_modules\cordova-common\src\ActionStack.js:56:25)
at Api.addPlugin (C:\dev\testusecase\myApp\node_modules\cordova-electron\lib\Api.js:132:24)
at handleInstall (C:\Users\m.hipper\AppData\Roaming\npm-cache_npx\32496\node_modules\cordova\node_modules\cordova-lib\src\plugman\install.js:561:10)
at C:\Users\m.hipper\AppData\Roaming\npm-cache_npx\32496\node_modules\cordova\node_modules\cordova-lib\src\plugman\install.js:344:28
at processTicksAndRejections (internal/process/task_queues.js:95:5)
Uh oh!
ENOENT: no such file or directory, open 'C:\dev\testusecase\myApp\platforms\electron\www\package.json'
Error: spawn C:\Windows\system32\cmd.exe ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
Information
I found the issue working on a native file system plugin for electron and was able to reproduce it with cordova-plugin-device since it was upgraded. When you install electron and then add the plugin everything works fine because the package json is already there. In the situation of source control and build servers however it fails because prepare which also installs plugins have a race condition on the package.json file inside electron\www (Different to the root project package.json).
While steps are listed below, i also have a repo with the issue: https://github.com/Serivy/cordova-electron-plugin-issue
Work around
I have a work around which is to add a hook before the plugin is installed to create an empty package.json file {} which the plugin install then populates, followed by the main meta data.
config.xml
<hook src="before_plugin_install.js" type="before_plugin_install" />
before_plugin_install.js
Command or Code
Create the app and add plugin
Reset like it would get it from source control in the .gitignore
Prepare the platform like in build servers
Environment, Platform, Device
Cordova electron application with electron plugin (eg: cordova-plugin-device )
I saw a similar comment here #211 (comment) but its on a separate kind of issue..
Version information
"cordova": "^11.0.0",
"cordova-electron": "^3.1.0",
"cordova-plugin-device": "^2.1.0"
Operating system: Windows 10
Checklist
The text was updated successfully, but these errors were encountered: