Electron-builder: Support for sibling packages (lerna + yarn workspaces)

Created on 24 Oct 2017  路  13Comments  路  Source: electron-userland/electron-builder

  • Version: 19.40.0
  • Target: any

Hi, following the support for hoisted node_modules in lerna + yarn workspaces in v19.39.0, I'm wondering if it would also be possible to support sibling packages as defined in the lerna.json packages config and/or the root package.json workspaces please?
I currently have a setup where my electron app is using sibling packages and electron-builder throws the "Error: Unresolved node modules" error for these dependencies.
Thanks!

feature

Most helpful comment

This issue will be addressed on this weekends (as we have sample project :)).

All 13 comments

Sample project please :)

Here it is: https://github.com/PaulLeCam/electron-builder-workspaces

I think the main issue comes from this dependency that is correctly resolved by lerna/yarn, but not by electron-builder: https://github.com/PaulLeCam/electron-builder-workspaces/blob/master/packages/app-desktop/package.json#L14

Was hoping for https://github.com/electron-userland/electron-builder/commit/b0fa409e2fc2d209a9c676442064fb4675c13d57 to fix this, but still not working for me. Checked out the sample project, same behavior.

The dependencies in the packages are missing, no node_modules folder present in there, only in the root directory.

Any ideas?

I will try to find time to investigate this issue soon.

Thanks, found out my yarn was overwritten by an old version, I am now on yarn 1.2.1. Tuned out my old yarn did not support workspaces yet.

Will investigate further, but looks like sub-dependencies of dependencies are missing in the bundles. Running electron directly from within my lerna package works fine. Tried it with module hoisting enabled and disabled.

Okay, the repo of @PaulLeCam has the same issue:

Uncaught Exception:
Error: Cannot find module 'serve'
    at Module._resolveFilename (module.js:470:15)
    at Function.Module._resolveFilename (/Users/bene/dev/electron-builder-workspaces/packages/app-desktop/dist/mac/app-desktop.app/Contents/Resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/bene/dev/electron-builder-workspaces/packages/app-desktop/dist/mac/app-desktop.app/Contents/Resources/app.asar/node_modules/app-server/index.js:2:15)
    at Object.<anonymous> (/Users/bene/dev/electron-builder-workspaces/packages/app-desktop/dist/mac/app-desktop.app/Contents/Resources/app.asar/node_modules/app-server/index.js:6:3)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)

serve is a dependency of package/app-server which gets not included into the electron-builder "binary".

Running electron from within the package/app-desktop via npm start works fine.

Steps to reproduce:

  • add "main": "main.js", to package.json of package/app-desktop
  • npm i
  • lerna bootstrap
  • lerna exec build
  • Run the app, on mac: open packages/app-desktop/dist/mac/app-desktop.app

screen shot 2017-11-01 at 18 27 56

Same issue for us in nteract, PR to introduce hoisting back in and upgrade electron-builder: https://github.com/nteract/nteract/pull/2102

We'd also love to switch to yarn workspaces, though we're running into issues with it and electron builder there too.

Does it make sense to mention also the use case of the link: dependency such as:

    "dependencies": {
        "foobar": "link:../foobar",

Currently, I have loads of missing dependencies by using such a pattern. Whether it should be supported or not is a good question, but if it is not, at least it would be nice if there was a heads-up warning...
Cheers

I'm experiencing the same issues with Unresolved node modules: when running [email protected]. We're using yarn workspaces to hoist dependencies/monorepo. It looks like the issue is that sub-dependencies of dependencies cannot be found or packaged into the binary, like @axe312ger pointed out.

How can we help to get this issue resolved?

I solved this for the moment by bundling first with Webpack. Webpack can correctly resolve the dependencies, so loading in the bundled JS and setting ELECTRON_BUILDER_ALLOW_UNRESOLVED_DEPENDENCIES=1 before running electron-builder works for now.

This issue will be addressed on this weekends (as we have sample project :)).

@develar Thanks for investigating!

Is there anything we can help to track this down?

Awesome @develar thx :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omarkilani picture omarkilani  路  3Comments

ccorcos picture ccorcos  路  3Comments

iklemm picture iklemm  路  3Comments

antonycourtney picture antonycourtney  路  3Comments

xingoxu picture xingoxu  路  3Comments