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

Having some dependencies in the package node_modules break the build #8376

Closed
arantes555 opened this issue Jul 24, 2024 · 4 comments
Closed

Comments

@arantes555
Copy link

  • Electron-Builder Version: tried on 24.13.3 & 24.6.4
  • Node Version: v20.12.2
  • Electron Version: tried with multiple versions
  • Electron Type (current, beta, nightly):
  • Target: Linux, MacOS, and Windows

This is a weird one.

The symptom I was having after updating my dependencies is that, the build worked fine, running the app graphically worked fine, but running it in a CLI mode failed with:

Error [ERR_REQUIRE_ESM]: require() of ES Module /tmp/.mount_SealdLpNtSLy/resources/app.asar/node_modules/wrap-ansi/node_modules/string-width/index.js from /tmp/.mount_SealdLpNtSLy/resources/app.asar/node_modules/wrap-ansi/index.js not supported.
Instead change the require of /tmp/.mount_SealdLpNtSLy/resources/app.asar/node_modules/wrap-ansi/node_modules/string-width/index.js in /tmp/.mount_SealdLpNtSLy/resources/app.asar/node_modules/wrap-ansi/index.js to a dynamic import() which is available in all CommonJS modules.
    at c._load (node:electron/js2c/node_init:2:17025)
    at Hook._require.Module.require (/tmp/.mount_SealdLpNtSLy/resources/app.asar/node_modules/require-in-the-middle/index.js:188:39)
    at Object.<anonymous> (/tmp/.mount_SealdLpNtSLy/resources/app.asar/node_modules/wrap-ansi/index.js:2:21) {
  code: 'ERR_REQUIRE_ESM'
}

This is surprising, as the version of string-width in my dependencies (well, my dependencies' dependencies) is 4.2.3 which is not ESM. See this result of npm ls string-width in my app directory:

➜  app git:(master) ✗ npm ls string-width
[email protected] /home/mehdi/Seald/zappa/app
└─┬ @seald/[email protected]
  └─┬ [email protected]
    ├─┬ [email protected]
    │ ├── [email protected] deduped
    │ └─┬ [email protected]
    │   └── [email protected] deduped
    └── [email protected]

However, when i tried unpacking the .asar built by electron-builder, and doing the npm ls in the unpacked directory, the results are different:

➜  asar_unpacked git:(master) ✗ npm ls string-width
npm ERR! code ELSPROBLEMS
npm ERR! extraneous: [email protected] /home/mehdi/Seald/zappa/releases_old/linux-unpacked/resources/asar_unpacked/node_modules/@isaacs/cliui/node_modules/string-width
npm ERR! invalid: [email protected] /home/mehdi/Seald/zappa/releases_old/linux-unpacked/resources/asar_unpacked/node_modules/wrap-ansi/node_modules/string-width
[email protected] /home/mehdi/Seald/zappa/releases_old/linux-unpacked/resources/asar_unpacked
├─┬ @isaacs/[email protected] extraneous
│ ├── [email protected] extraneous
│ └─┬ [email protected] invalid: "^8.1.0" from node_modules/@isaacs/cliui
│   └── [email protected] invalid: "^4.1.0" from node_modules/wrap-ansi
├─┬ wrap-ansi-cjs@npm:[email protected] extraneous
│ └── [email protected]
└─┬ [email protected]
  ├─┬ [email protected]
  │ └── [email protected] deduped
  └── [email protected] deduped


npm ERR! A complete log of this run can be found in:
npm ERR!     /home/mehdi/.npm/_logs/2024-07-24T09_16_16_648Z-debug-0.log

At first, I did not understand at all where these dependencies were coming from. What it appears is that they are coming from the parent directory. I have no idea why electron-builder adds them to the build. So, in my case, if any of the dependencies in the project's directory (the root, not the app folder) has any newer version of string-width anywhere in its dependency tree, it is the one added in the in the root of my package in the asar, no idea why. And as it is a sub-dependency of glob@10, more and more packages depend on it indirectly.

In my case, to work around the problem, I had to rollback @rollup/plugin-commonjs to 25.0.8 as the 26 updates glob, plus I had to install [email protected] in my direct dev dependencies to avoid it being updated to semver-compatible 0.2.6 (which uses glob@10) when it is an indirect dependency (and it is a dependency of electron-builder itself through [email protected]).

I don't know if my explanations are very clear, sorry for being a bit rambly, this problem was very confusing.

Don't hesitate to ask if you have any more questions to help you debug, or if you need me to try out anything.

@mmaietta
Copy link
Collaborator

Can you try next v25.0.2 and see if that produces a different result? There were some node module copying changes/fixes that went in so I'm curious if that'll resolve your issue

@arantes555
Copy link
Author

@mmaietta That is non-trivial for me because of #8351 (which is not fixed in v25.0.2), but I'll try to reproduce on a Mac and let you know.

@arantes555
Copy link
Author

@mmaietta After testing on Mac, I can confirm v25.0.2 does seem to fix the problem. I just can't use it yet because of the aforementioned issue.

@arantes555
Copy link
Author

@mmaietta i guess we can close this now, as v25 seems to fix the problem

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

No branches or pull requests

2 participants