adopted-ember-addons / ember-electron

:zap: Build, test, compile and package desktop apps with Ember and Electron
https://ember-electron.js.org/
Other
805 stars 109 forks source link

Default electronWinstallerConfig name property causes failure #163

Closed jacobq closed 6 years ago

jacobq commented 7 years ago

By default, it appears that the package.json file changes generated when running this blueprint cause an error when trying to build a squirrel target on Windows because the name field is set to an empty string (not allowed). I think it would be better to omit this property altogether so that the default (name field from package.json) will be used unless another value is specified. Otherwise other developers may be confused by the unexpected error message that can occur if this is not the case:

√ Packaging Application

Cleaning tmp build files
An error occured while making for target: squirrel
Failed with exit code: 1
Output:
Attempting to build package from '.nuspec'.
Id is required.

Error: Failed with exit code: 1
Output:
Attempting to build package from '.nuspec'.
Id is required.

    at ChildProcess.proc.on.code (C:\Users\jacob\Documents\ember-electron-update-test\node_modules\electron-winstaller\lib\spawn-promise.js:62:16)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
jacobq commented 7 years ago

This might be an upstream problem: https://github.com/electron-userland/electron-forge/blob/master/tmpl/package.json

jacobq commented 7 years ago

Seems there is a similar problem with windowsStoreConfig; it doesn't work out-of-the-box if the author field of package.json is a string like First Last <first.last@example.com>:

An error occured while making for target: appx
C:\Program Files (x86)\Windows Kits\10\bin\x64\makeappx.exe exited with code: 1
Error: C:\Program Files (x86)\Windows Kits\10\bin\x64\makeappx.exe exited with code: 1
    at ChildProcess.child.on (C:\Users\jacob\Documents\ember-electron-update-test\node_modules\electron-windows-store\lib\utils.js:74:23)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
malept commented 7 years ago

(FYI, the issue reporter has filed electron-userland/electron-forge#161 to fix the other issue.)

bendemboski commented 6 years ago

@jacobq I know some upstream fixes have been made...can you check to see if this still repros?

jacobq commented 6 years ago

@bendemboski Sure, I will try recreating a dummy project tomorrow to see if it still happens.

jacobq commented 6 years ago

Tested on Windows 10.0.15063 (64-bit) virtual machine with node v8.9.1 / npm v5.5.1 / ember-cli 2.16.2. Command sequence (as executed from non-elevated git-bash / MINGW64 shell) is as follows:

$ ember new my-app
# (output omitted)
$ cd my-app
$ ember install ember-electron # used v2.7.2

NPM: Installed ember-electron
installing ember-electron
  create ember-electron\.compilerc
  create ember-electron\main.js
  create ember-electron\test-main.js
  create testem-electron.js
Project needs forge config
Cannot read property 'replace' of undefined
TypeError: Cannot read property 'replace' of undefined
    at setInitialForgeConfig (C:\Users\jacob\Documents\temp\my-app\node_modules\electron-forge\dist\util\forge-config.js:85:78)
    at C:\Users\jacob\Documents\temp\my-app\node_modules\electron-forge\dist\api\import.js:292:44
    at Generator.next (<anonymous>)
    at Generator.tryCatcher (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\util.js:16:23)
    at PromiseSpawn._promiseFulfilled (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\generators.js:97:49)
    at Promise._settlePromise (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\promise.js:574:26)
    at Promise._settlePromise0 (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\promise.js:693:18)
    at Async._drainQueue (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\async.js:133:16)
    at Async._drainQueues (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\async.js:143:10)
    at Immediate.Async.drainQueues (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)

This is not the same problem, but it surprised me. Am I forgetting a step of how to setup a new project? (I haven't done it in a while.)

When I run w/ debugging output I get:

$ DEBUG=*,-ember-cli-babel ember install ember-electron
# ... (previous output omitted) ...
Mon, 27 Nov 2017 14:09:26 GMT ember-cli:project addon: loader.js
Mon, 27 Nov 2017 14:09:27 GMT ember-cli:blueprint START: processing blueprint: `ember-electron`
2017-11-27T14:09:27.723Z electron-forge:import Attempting to import project in: C:\Users\jacob\Documents\temp\my-app
2017-11-27T14:09:27.723Z electron-forge:init:git .git directory already exists, skipping git initialization
2017-11-27T14:09:27.723Z electron-forge:import reading current scripts object: { build: 'ember build',
  start: 'ember server',
  test: 'ember test' }
2017-11-27T14:09:27.723Z electron-forge:import forgified scripts object: { build: 'ember build',
  start: 'ember server',
  test: 'ember test' }
2017-11-27T14:09:27.723Z electron-forge:import deleting old dependencies forcefully
2017-11-27T14:09:27.723Z electron-forge:import installing dependencies
2017-11-27T14:09:27.754Z electron-forge:dependency-installer installing ["electron-compile","electron-squirrel-startup"] in: C:\Users\jacob\Documents\temp\my-app dev=false,exact=false,withYarn=false
2017-11-27T14:09:27.754Z electron-forge:dependency-installer executing ["install","electron-compile","electron-squirrel-startup","--save"] in: C:\Users\jacob\Documents\temp\my-app
2017-11-27T14:09:27.754Z electron-forge:runtime-config fetching key verbose
2017-11-27T14:10:09.489Z electron-forge:import installing devDependencies
2017-11-27T14:10:09.489Z electron-forge:dependency-installer installing ["babel-preset-env","babel-preset-react","babel-plugin-transform-async-to-generator","electron-forge"] in: C:\Users\jacob\Documents\temp\my-app dev=true,exact=false,withYarn=false
2017-11-27T14:10:09.489Z electron-forge:dependency-installer executing ["install","babel-preset-env","babel-preset-react","babel-plugin-transform-async-to-generator","electron-forge","--save-dev"] in: C:\Users\jacob\Documents\temp\my-app
2017-11-27T14:10:09.489Z electron-forge:runtime-config fetching key verbose
2017-11-27T14:10:43.380Z electron-forge:import installing exactDevDependencies
2017-11-27T14:10:43.380Z electron-forge:dependency-installer installing ["electron-prebuilt-compile"] in: C:\Users\jacob\Documents\temp\my-app dev=true,exact=true,withYarn=false
2017-11-27T14:10:43.380Z electron-forge:dependency-installer executing ["install","electron-prebuilt-compile","--save-exact","--save-dev"] in: C:\Users\jacob\Documents\temp\my-app
2017-11-27T14:10:43.380Z electron-forge:runtime-config fetching key verbose
Mon, 27 Nov 2017 14:11:27 GMT ember-cli:blueprint END: processing blueprint: `ember-electron` in (120173ms)
Mon, 27 Nov 2017 14:11:27 GMT ember-cli:command An error occurred running `AddonInstall` from the `install` command. TypeError: Cannot read property 'replace' of undefined
    at setInitialForgeConfig (C:\Users\jacob\Documents\temp\my-app\node_modules\electron-forge\dist\util\forge-config.js:85:78)
    at C:\Users\jacob\Documents\temp\my-app\node_modules\electron-forge\dist\api\import.js:292:44
    at Generator.next (<anonymous>)
    at Generator.tryCatcher (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\util.js:16:23)
    at PromiseSpawn._promiseFulfilled (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\generators.js:97:49)
    at Promise._settlePromise (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\promise.js:574:26)
    at Promise._settlePromise0 (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\promise.js:693:18)
    at Async._drainQueue (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\async.js:133:16)
    at Async._drainQueues (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\async.js:143:10)
    at Immediate.Async.drainQueues (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)
Cannot read property 'replace' of undefined
TypeError: Cannot read property 'replace' of undefined
    at setInitialForgeConfig (C:\Users\jacob\Documents\temp\my-app\node_modules\electron-forge\dist\util\forge-config.js:85:78)
    at C:\Users\jacob\Documents\temp\my-app\node_modules\electron-forge\dist\api\import.js:292:44
    at Generator.next (<anonymous>)
    at Generator.tryCatcher (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\util.js:16:23)
    at PromiseSpawn._promiseFulfilled (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\generators.js:97:49)
    at Promise._settlePromise (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\promise.js:574:26)
    at Promise._settlePromise0 (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\promise.js:693:18)
    at Async._drainQueue (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\async.js:133:16)
    at Async._drainQueues (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\async.js:143:10)
    at Immediate.Async.drainQueues (C:\Users\jacob\Documents\temp\my-app\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)
jacobq commented 6 years ago

Peeking at the EmberJS #e-electron channel, it looks like this is related to https://github.com/electron-userland/electron-forge/pull/372

jacobq commented 6 years ago

Re-running w/ productName: "my-app", added to package.json resulted in successfully addon installation (though still not successful packaging), though I first had to remove node_modules and re-run npm install to fix the error shown below (also ran elevated but don't think that was necessary):

Weird (I blame Windows) glitch with npm (corrected w/ nombom):

...
npm ERR! path C:\Users\jacob\Documents\temp\my-app\node_modules\get-folder-size\                                  node_modules
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall scandir
npm ERR! Error: EPERM: operation not permitted, scandir 'C:\Users\jacob\Document                                  s\temp\my-app\node_modules\get-folder-size\node_modules'
...

Successful installation after editing package.json:

$ ember install ember-electron
NPM: Installed ember-electron
installing ember-electron
  identical ember-electron\.compilerc
  identical ember-electron\main.js
  identical ember-electron\test-main.js
  identical testem-electron.js
Project needs forge config
NPM: Installed devtron@^1.4.0
NPM: Installed electron-protocol-serve@^1.3.0
Installed electron build tools
Created ember-electron resource dirs
Extracted ember-electron forge config
Installed addon package.

Almost packaged (got stuck at "Authors"):

$ ember electron:make

"ember-welcome-page" was detected in your devDependencies!
Please note that this addon only works in development environment
and will not render in production mode. It is safe to uninstall
this addon once you removed the {{welcome-page}} template tag.

cleaning up...
Built and assembled Electron project successfully. Stored in "C:\Users\jacob\Documents\temp\my-app\tmp\package_task-tmp_path-XAJEMLDp.tmp".
Packaging Electron project.
Failed to compile file: C:\Users\jacob\AppData\Local\Temp\electron-packager\win32-x64\my-app-win32-x64\resources\app\ember\crossdomain.xml
Compiling C:\Users\jacob\AppData\Local\Temp\electron-packager\win32-x64\my-app-win32-x64\resources\app\ember\crossdomain.xml resulted in a MIME type of application/xml, which we don't know how to handle
√ Compiling Application
√ Preparing native dependencies
Making Electron project.
An error occured while making for target: squirrel
Failed with exit code: 1
Output:
Attempting to build package from 'my_app.nuspec'.
Authors is required.

Error: Failed with exit code: 1
Output:
Attempting to build package from 'my_app.nuspec'.
Authors is required.

    at ChildProcess.proc.on.code (C:\Users\jacob\Documents\temp\my-app\node_modules\electron-winstaller\lib\spawn-promise.js:62:16)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)

Manually edited electron-forge-config.js:

Replaced this:

  ...
  "electronWinstallerConfig": {
    "name": "my_app"
  },
  ...

with this:

  "electronWinstallerConfig": {
    "name": "my_app",
    "authors": "Jane Doe <jane.doe@example.com>"
  },

(Added "authors") This seems to have worked,

Successful packaging after adding authors field to electron-forge-config.js:

$ ember electron:make

"ember-welcome-page" was detected in your devDependencies!
Please note that this addon only works in development environment
and will not render in production mode. It is safe to uninstall
this addon once you removed the {{welcome-page}} template tag.

cleaning up...
Built and assembled Electron project successfully. Stored in "C:\Users\jacob\Documents\temp\my-app\tmp\package_task-tmp_path-Bm6Eph8e.tmp".
Packaging Electron project.
Failed to compile file: C:\Users\jacob\AppData\Local\Temp\electron-packager\win32-x64\my-app-win32-x64\resources\app\ember\crossdomain.xml
Compiling C:\Users\jacob\AppData\Local\Temp\electron-packager\win32-x64\my-app-win32-x64\resources\app\ember\crossdomain.xml resulted in a MIME type of application/xml, which we don't know how to handle
√ Compiling Application
√ Preparing native dependencies
Making Electron project.

Since most real projects have author defined in package.json I figured I should try editing that instead of adding the change described above. Unfortunately, copying the line added in the previous section, pasting in package.json, removing the s from authors, and re-running did not work. Instead it produced the same Authors is required message.

Thinking that maybe if I had had author defined in package.json when installing ember-electron it might have used it to populate electronWinstallerConfig I tried again:

$ rm -rf electron-out/ ember-electron/
# (manually edit package.json to remove electron-forge config)
$ ember generate ember-electron
installing ember-electron
  identical ember-electron\.compilerc
  identical ember-electron\main.js
  identical ember-electron\test-main.js
  identical testem-electron.js
Project needs forge config
NPM: Installed devtron@^1.4.0
NPM: Installed electron-protocol-serve@^1.3.0
Installed electron build tools
Created ember-electron resource dirs
Extracted ember-electron forge config
$ ember electron:make

"ember-welcome-page" was detected in your devDependencies!
Please note that this addon only works in development environment
and will not render in production mode. It is safe to uninstall
this addon once you removed the {{welcome-page}} template tag.

cleaning up...
Built and assembled Electron project successfully. Stored in "C:\Users\jacob\Documents\temp\my-app\tmp\package_task-tmp_path-OHpOexnt.tmp".
Packaging Electron project.
Failed to compile file: C:\Users\jacob\AppData\Local\Temp\electron-packager\win32-x64\my-app-win32-x64\resources\app\ember\crossdomain.xml
Compiling C:\Users\jacob\AppData\Local\Temp\electron-packager\win32-x64\my-app-win32-x64\resources\app\ember\crossdomain.xml resulted in a MIME type of application/xml, which we don't know how to handle
√ Compiling Application
√ Preparing native dependencies
Making Electron project.

This seems to have worked, though it did not add authors to electronWinstallerConfig so I have no idea why this worked and not my previous attempt. I suppose it's possible that something wasn't saved or was cached or I made a typo or something.

I will go ahead and close this issue because ember electron:make succeeds now (assuming authors is defined in electron-forge-config.js or author is defined in package.json [at least at the time of installing the addon] and productName is defined in package.json [or upstream electron-forge fix gets merged]).

bendemboski commented 6 years ago

Great, thanks a lot for the investigation @jacobq. Please re-open this if it rears its head again!