Getting this error message suddenly. Might have something to do with 7zip-bin-osx being renamed to 7zip-bin-mac?:
electron-builder 19.27.0
Using electron-builder.json configuration file
No native production dependencies
Packaging for darwin x64 using electron 1.7.6 to dist/mac
Downloading tmp-27704-1-SHASUMS256.txt-1.7.6
[============================================>] 100.0% of 2.93 kB (2.93 kB/s)
Error: Cannot find module '7zip-bin-mac'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (<project-path>/node_modules/7zip-bin/index.js:13:67)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at _load_zipBin (<project-path>/node_modules/electron-builder/out/packager/dirPackager.js:60:22)
error Command failed with exit code 255.
If you use NPM — do not use it. Please remove node_modules and install using yarn.
I'm using yarn
Looks like 7zip-bin-mac is not installed in node_modules.. :/ only 7zip-bin..
getting
warning [email protected]: The platform "darwin" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
warning [email protected]: The platform "darwin" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
But no warnings for mac :|
Maybe did you disable optional dependencies installing (https://docs.npmjs.com/misc/config#optional) ignore-optional
?
@develar Unfortunately no :(
Please install as optional dependency in your project as workaround:
"optionalDependencies": {
"7zip-bin-mac": "^1.0.1",
},
Just ran into this. rm -rf ./node_modules && rm yarn.lock && yarn install
fixed it.
We had a similar problem. In our case, it seems to occur because "packages-lock.json" is generated by "npm i" (npm v5.3) on Windows, committed to git, and then used to build on Mac (on Travis).
It seems that packages.lock only mentions that "electron-builder" requires "7zip-bin" which then requires"7zip-bin-win" and does not mention "7zip-bin-mac".
@develar How do you recommend we deal with this (since you are author of 7zip-bin where both 7zip-bin-win and 7zip-bin-mac are listed as optional dependencies)? Or is this something that is solved by using yarn?
NEVER use npm
. Especially, NEVER use package–lock.json npm
has a lot of bugs and each new version add new ones. Do not waste your time — just use reliable, fast, stable yarn.
I used to prefer Yarn but recent versions of npm work just fine to be honest. I think the issue is that electron-builder has been developed with yarn only and relies on its peculiarities. Maybe the doc should be updated to reflect this - instead of "Yarn is strongly recommended instead of npm" it should be "Yarn is required. It will NOT work with npm."
In our case we would not mind using yarn. However, at this point, we depend on "electron-angular-toolkit", which seems to be unmaintained, and doesn't like npm.
This is because we use webpack and angular-cli, which has some problems due to the way they interact (or don't interact).
I believe we worked around this by configuring CI to have separate node-modules for each target platform, and running each build in the same environment as the target platform.
It would be great if electron-builder could work directly with webpack+angular-cli, as we could use plain yarn. At the present, we are kind of stuck with npm.
has been developed with yarn only and relies on its peculiarities
No. Even more — we keep compatibility with NPM 3 and all other NPM versions and that's why we don't use scoped modules. Just to be sure that electron-builder doesn't force you to use some specific package manager or version.
@develar, however this bug with missing module "7zip-bin-mac" can only be resolved by using yarn, or am I missing something? I've just switched my project from npm to yarn and that solved that particular bug, however now I'm hitting a different yarn bug that's been unresolved for over a year.
am I missing something
As stated, NPM is unreliable and buggy. The only solution to fix this issue and support NPM — do not use optional dependencies. Yes — I didn't report this bug to NPM and didn't investigate. Why? Because I don't want to waste my time. Yarn works for me and has a lot of another advantages and so, no reason to try to use NPM.
@develar (prob this is not the correct place but since its where we encountered the blocker to move to yarn...) do you know of anyone/any-project using electron-builder directly with angular-cli and webpack (without resorting to eject)?
May be it helps to somebody. In my case when I had this error, optional package installation was disabled.
To check it run npm config list
and notice optional
setting. If it false
try to set it by npm config set optional true
and reinstall packages by npm install
.
And @develar don't push people to change something because you or your soft don't like this "something". Usually people can't just change it when the product in production or the team accustomed to present choice. Any change cost money. And by the way after all each soft has bugs. Yarn isn't an exception.
FYI - Potential fix for this and related issues over yonder: https://github.com/develar/7zip-bin/pull/5
This issue will happen anytime the same lockfile is used with yarn|npm install
when run a different platform than the platform the lockfile was generated on.
So strange that NPM even for a new format did the same critical mistake (along others) and still it is not fixed.
@Eshva and other — sorry. I will reopen issue.
electron-builder 20.14.4+ doesn't use optional dependencies. Enjoy.
Most helpful comment
May be it helps to somebody. In my case when I had this error, optional package installation was disabled.
To check it run
npm config list
and noticeoptional
setting. If itfalse
try to set it bynpm config set optional true
and reinstall packages bynpm install
.And @develar don't push people to change something because you or your soft don't like this "something". Usually people can't just change it when the product in production or the team accustomed to present choice. Any change cost money. And by the way after all each soft has bugs. Yarn isn't an exception.