electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.29k stars 487 forks source link

Yarn local workspaces no longer working - fails on Preparing native dependencies #3597

Open joezappie opened 2 weeks ago

joezappie commented 2 weeks ago

Pre-flight checklist

Electron Forge version

7.4.0

Electron version

30.0.3

Operating system

Windows 10

Last known working Electron Forge version

7.2.0

Expected behavior

I had an issue #3388 about using yarn workspaces for a monorepo where the my electron app depends on other local workspace packages. At the time 7.2.0 was out and @easternmotors was able to show me how to configure yarn to get it to build using the workspaces: protocol.

Upgrading that test repo to 7.4.0, it now crashes on the "Preparing native dependencies" step. image

I'm new to yarn but it doesn't appear to output any error on the crash. Running make with npm instead crashes on the same step and provides an unhelp generic error:

npm ERR! Lifecycle script `make` failed with error:
npm ERR! Error: command failed
npm ERR!   in workspace: electron-app@1.0.0
npm ERR!   at location: C:\Users\joeja\projects\yarn-electron-workspaces\packages\electron-app

This test repo is just an electron app created with the command yarn create electron-app electron-app --template vite and a local workspace test package added to its dependencies, so very easy to repeat.

Actual behavior

It should build when a local workspace is used as a dependency

Steps to reproduce

I have two repo to simulate it was working on 7.2 and failing on 7.4:

7.4.0 Fail Test Repo

  1. Clone test repo using electron-forge 7.4.0: https://github.com/joezappie/yarn-electron-workspaces/tree/bug/electron-forge-make
  2. Run `yarn workspace electron-app make'
  3. See that it crashes on the Preparing native dependencies step

7.2.0 Success Test Repo

  1. Clone test repo using electron-forge 7.2.0: https://github.com/joezappie/yarn-electron-workspaces
  2. Run `yarn workspace electron-app make'
  3. See that it successfully builds

Additional information

I tried 7.3.0/7.3.1 but I run into an an error saying electron-forge/plugin-vite needed to be in my dev dependencies, despite being in it so I gave up on those versions. Not sure if its 7.3 or 7.4 that broke the module resolution of local workspaces dependencies.

Is there now a different way of needing to do this?

easternmotors commented 2 weeks ago

@joezappie hey I saw your issue but I have been travelling and haven't been able to test this out. I can say I do have it working with 7.4.0 without any major changes. I'll let you know if I can repro/fix using your minimal repo when I get a chance.

Let me know if you've solved the issue already though!

easternmotors commented 1 week ago

@joezappie I actually misspoke in my last post, I forgot we refactored our app in a way that we don't actually cross-reference Yarn workspaces anymore in our app which is why I haven't seen the issue. Regardless I was curious and wanted to dive into the issue a little deeper.

It seemed to be failing on the package command (which is a subset of the make command). To get some better output, I ran the following command:

# Basic debugging output
DEBUG=1 yarn workspace electron-app run package

# electron-packager debugging output (this gave me more info once I narrowed it down to electron-packager)
DEBUG=electron-packager yarn workspace electron-app run package

Running either of those gave me a better error message:

An unhandled rejection has occurred inside Forge:
Error: EPERM: operation not permitted, symlink 'C:\...\yarn-electron-workspaces\packages\test' -> 'C:\Users\...\AppData\Local\Temp\electron-packager\tmp-I0C8Ti\node_modules\test-package'

I have run into weird permission errors on Windows before so I hopped over to my MacBook Pro and I confirmed that the command is working as expected on Mac. So, I hopped back to my PC and was trying a bunch of different things to no avail. I finally ended up trying to run Git Bash as administrator and got it to work.

I'm not sure exactly what change in electron-forge and/or electron-packager necessitated this change but hopefully it give you a workaround for the situation.

Just for your SA, the other things I tried on Windows that didn't end up working were messing with Yarn's winLinkType config option and setting electron-packager's tmpdir option to false in the forge.config.js. The latter might be a viable option once this issue is resolved.

I hope this helps and let me know if launching your terminal with administrator privileges works and if that's a viable solution for you.