Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Packager confusion #113

Closed
mnichols opened this issue Jul 10, 2016 · 15 comments
Closed

Packager confusion #113

mnichols opened this issue Jul 10, 2016 · 15 comments

Comments

@mnichols
Copy link

mnichols commented Jul 10, 2016

I've tried walking through every comment in this thread but can't seem to quite get packaging with this lib to work:
To be clear, I am trying to use a 'two package.json' approach (similar to electron-builder) because of the weight of combining the two.

So given this dir structure:

- root/
   - package.json
   - src/
      - package.json
      - index.js
      - main/
         - index.js
      - render/
         - index.js
         - index.html

my npm script in root package.json is:

# Note that I am calling packager on the 'src' dir since I read calling it 'app' causes problems
"app:Darwin": "electron-packager-compile ./src --version=1.2.5 --platform=darwin --arch=all --asar --overwrite --out=build"

When run $> open ./build/agent-ui-app-darwin-x64/agent-ui-app.app

I get this error:

Uncaught Exception:
Error: Asked for /Users/mnichols/dev/pqls/apps/ui/build/agent-ui-app-darwin-x64/agent-ui-app.app/Contents/Resources/app.asar/index.js but it was not precompiled!
    at FileChangedCache.getHashForPathSync (/Users/mnichols/dev/pqls/apps/ui/build/agent-ui-app-darwin-x64/agent-ui-app.app/Contents/Resources/app.asar/node_modules/electron-compile/lib/file-change-cache.js:356:17)
    at CompilerHost.compileReadOnlySync (/Users/mnichols/dev/pqls/apps/ui/build/agent-ui-app-darwin-x64/agent-ui-app.app/Contents/Resources/app.asar/node_modules/electron-compile/lib/compiler-host.js:687:43)
    at CompilerHost.compileSync (/Users/mnichols/dev/pqls/apps/ui/build/agent-ui-app-darwin-x64/agent-ui-app.app/Contents/Resources/app.asar/node_modules/electron-compile/lib/compiler-host.js:644:39)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/mnichols/dev/pqls/apps/ui/build/agent-ui-app-darwin-x64/agent-ui-app.app/Contents/Resources/app.asar/node_modules/electron-compile/lib/require-hook.js:32:48)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Module.require (module.js:466:17)
    at Object.init (/Users/mnichols/dev/pqls/apps/ui/build/agent-ui-app-darwin-x64/agent-ui-app.app/Contents/Resources/app.asar/node_modules/electron-compile/lib/config-parser.js:372:16)
    at Object.<anonymous> (/Users/mnichols/dev/pqls/apps/ui/build/agent-ui-app-darwin-x64/agent-ui-app.app/Contents/Resources/app.asar/es6-shim.js:8:17)

UPDATE
Note that when package without asar and manually include the .cache inside the .app directory it works just fine!

Do I need to manually run electron-compile to get a .cache dir somewhere to be included in the resulting app.asar? My understanding this was already done under the hood but I can't make sense of it.

Any pointers?

@mnichols
Copy link
Author

More details...this exact workflow works from npm scripts:

"app:Darwin": "npm run clean && electron-packager-compile ./src --version=1.2.5 --platform=darwin --arch=all --overwrite --out=build",
"compilecache": "electron-compile --appdir=./src ./src",
"copycache": "cp -r ./src/.cache build/agent-ui-darwin-x64/agent-ui.app/Contents/Resources/app/",
"postapp:Darwin": "npm run compilecache && npm run copycache"

NOTE this isnt using asar archiving but it does result in a working app using electron-compile with a two-package.json setup.

When I include the .cache in the ./src dir before running electron-packager-compile the cache is included but somehow I get 'isnt precompiled' errors. But if I manually include the cache after the packaging is done it works.

@anaisbetts
Copy link
Contributor

Hm, I wonder if we're not copying over the entire cache somehow :-/

@mnichols
Copy link
Author

@paulcbetts That is precisely the issue! I just ran the two commands to compare:
with asar
electron-packager-compile ./src --version=1.2.5 --platform=darwin --arch=all --asar --overwrite --out=build
compile only
electron-compile --appdir=./src ./src

When I asar extract the result of the first command and compare the contents of the .cache dir, I am missing one file compared to the result of electron-compile.

~/dev/pqls/apps/ui$ ls -a src/.cache/
.                       7f5749a966c21214c1a1dab36fb6fcb4536dac86    a6ff080d72ec4d56a33acd957959590114fb1fef
..                      8bdca42c68ad8750be336de3aeafae9314c31e5e    compiler-info.json.gz
~/dev/pqls/apps/ui$ ls -a ~/temp/pqlsapp/.cache
.                       7f5749a966c21214c1a1dab36fb6fcb4536dac86    compiler-info.json.gz
..                      a6ff080d72ec4d56a33acd957959590114fb1fef

@mnichols
Copy link
Author

After some more poking at the cause of this, it looks like it is always the main file (from package.json) which is excluded. All other files are included in the .cache which is used in the app.asar.

@anaisbetts
Copy link
Contributor

Yep, I think I know what this is. I'll fix this today or tomorrow. Thanks @mnichols for the solid write-up!

@mnichols
Copy link
Author

Thanks..I tried to creep through the code but had a hard time figuring out
why it happend. I see the compiler run on the file but the cacheEntry
collection doesnt seem to receive the hash mapping for it. I ran out of
time tracking it but it is really well done. Nice work, mate.

On Tue, Jul 19, 2016 at 11:43 AM, Paul Betts [email protected]
wrote:

Yep, I think I know what this is. I'll fix this today or tomorrow. Thanks
@mnichols https://github.com/mnichols for the solid write-up!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#113 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAsC9RiS-GcBpy19_jRJZOkZ8e9py0Qks5qXQzOgaJpZM4JI7sJ
.

@anaisbetts
Copy link
Contributor

This is fixed in 3.3.5, thanks all for helping track this down

@mnichols
Copy link
Author

mnichols commented Jul 23, 2016

Hi @paulcbetts , I'm afraid this isn't fixed.
To illustrate I created a repo that has both a working simple application using electron-compile and a broken application. The problem comes down to the packaging choking when there are subdirectories, regardless of whether the files are used or not.

  • The master branch works, even with asar (the non-broken version).
  • The subdirs branch doesnt work because the top-level 'index.js' isnt getting put into the cache. The only different between the two branches is the inclusion of a subdirectory nocollision in the src directory. Note that the files in there are not imported at all. They are simply in the tree.

I included a README there that illustrates how to run the app and package+run it.

@mnichols
Copy link
Author

@paulcbetts more investigating...it turns out even if I do a flat file structure (single package.json), having subdirectories cause failure.
I looked at the contents of the resulting package when there isnt a subdirectory and it turns out that a .cache is only created when there is a subdirectory in the target directory being packaged. If that subdir is removed, then a .cache isnt included at all...almost like it skips doing caching altogether if there arent subs. That's why it is 'working' without subdirectories.
The .cache is still failing because the very first file which is the 'main' script configured in the package.json isnt included in its cache collection. It doesnt matter what the name is.

@anaisbetts anaisbetts reopened this Jul 24, 2016
@SCLeoX
Copy link

SCLeoX commented Aug 17, 2016

@mnichols Do you have electron-compile installed in the src folder?

@mnichols
Copy link
Author

I did, yes.

On Wed, Aug 17, 2016 at 3:55 PM, SCLeo [email protected] wrote:

@mnichols https://github.com/mnichols Do you have electron-compile
installed in the src folder?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#113 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAsCwOR_uSZk6MNsXgLmgyaLbrXb6s2ks5qg5FkgaJpZM4JI7sJ
.

@SCLeoX
Copy link

SCLeoX commented Aug 17, 2016

@mnichols Nice, so we ran into exactly same problem XD

@mnichols
Copy link
Author

Yeh I had to abandon using this lib due to .cache oddities unfortunately.
It's got great potential but I ran out of time trying to debug the issue.
I'm hoping to pick it back up later.

On Wed, Aug 17, 2016 at 3:59 PM, SCLeo [email protected] wrote:

@mnichols https://github.com/mnichols Nice, so we ran into exactly same
problem XD


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#113 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAsC7Qyr9xk0sXMC9ILA4Rq7LU_Dpybks5qg5JAgaJpZM4JI7sJ
.

@SCLeoX
Copy link

SCLeoX commented Aug 17, 2016

The only difference between us is that I still get "it was not precompiled!" errors even though I drag it to resources folder manually. XD
I just spent like 5 hours on this thing. It is 7am here and I think I am gonna give up and switch to gulp or grunt. ._.

@malept
Copy link
Member

malept commented Mar 16, 2017

electron-packager-compile has been removed from this project due to its unreliability (see: most of the issues marked electron-packager in this issue tracker). It's now recommended to use the Electron Forge project, because it uses both electron-compile and Electron Packager (among other community projects) to create distributable Electron apps.

If the .cache bug still occurs with Electron Forge, please let us know.

@malept malept closed this as completed Mar 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants