Skip to content
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

local dependencies (file:path instead of version) are not included in app.asar #8401

Closed
flexopticalHenno opened this issue Aug 6, 2024 · 6 comments · Fixed by #8406
Closed

Comments

@flexopticalHenno
Copy link

  • Electron-Builder Version: 25.0.0, 25.0.1, 25.0.2
  • Node Version: 20.16.0, 18.20.4
  • Electron Version: 31.3.1
  • Electron Type (current, beta, nightly): current
  • Electron-Updater Version: 6.3.2, 6.2.1
  • Target: Win32 x64 NSIS

When packing the app with electron-builder, a local dependency (version is file:path/to/lib) is not included in app.asar/node_modules. This was working with electron-builder 24.13.3

When installing the local dependency, npm creates a symbolic link in the node_modules folder that points to the source of the dependency on the local file system. Electron-builder 24.13.3 created a copy of that folder in app.asar, but with electron-builder 25 it is missing. Starting the app will show an error dialog stating "Uncaught Exception: Error: Cannot find module 'name-of-local-dependency'".

@beyondkmp
Copy link
Collaborator

I wrote a small demo myself and couldn't reproduce the issue you mentioned.

hello.zip

Could you provide a demo code that reproduces the problem?

@flexopticalHenno
Copy link
Author

@beyondkmp
Copy link
Collaborator

beyondkmp commented Aug 7, 2024

I'm sorry for the inconvenience caused. This is caused by develar/app-builder#120. When npm installs local dependencies, it creates a system link. Currently, app-builder converts these system links into real paths, which causes the !libs to also filter out node_modules/hello-world.

It seems we can't revert develar/app-builder#120 as it would cause other issues.

There are three solutions:

  1. Use yarn.
  2. Use pnpm.
  3. If continuing with npm, use the following workaround: implement a post-install script.
{
  "scripts": {
    "postinstall": "node scripts/copy-local-deps.js"
  }
}
const fs = require('fs-extra');
const path = require('path');

const src = path.resolve(__dirname, '../libs/hello-world');
const dest = path.resolve(__dirname, '../node_modules/hello-world');


if (fs.existsSync(dest)) {
  fs.removeSync(dest);
}


fs.copySync(src, dest);
console.log('Local dependency copied successfully');

@mmaietta Do you have any suggestions or comments?

@flexopticalHenno
Copy link
Author

Thank you for the quick response and help. I believe that the third option will be working fine in my setup

@flexopticalHenno
Copy link
Author

Interestingly enough, when I try to reproduce this in your demo with files: ["**/*", "!test"] it will pack the local dependency into app.asar. If I move the dependency into a subfolder libs/test and exclude libs instead, test will not be part of node_modules in app.asar

@beyondkmp
Copy link
Collaborator

Interestingly enough, when I try to reproduce this in your demo with files: ["**/*", "!test"] it will pack the local dependency into app.asar. If I move the dependency into a subfolder libs/test and exclude libs instead, test will not be part of node_modules in app.asar

This should be a bug, which will be fixed in this #8406. Once fixed, you should not encounter any more issues if you directly place it in the libs directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants