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

Building app does not work with yarn workspaces that depend on each other #3388

Closed
3 tasks done
joezappie opened this issue Oct 24, 2023 · 7 comments
Closed
3 tasks done

Comments

@joezappie
Copy link

joezappie commented Oct 24, 2023

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

6.4.2

Electron version

27.0.2

Operating system

Windows 10 22H2

Last known working Electron Forge version

N/A

Expected behavior

Building apps in a yarn workspace should properly resolve dependencies

Actual behavior

Dependencies are missing

Steps to reproduce

  1. Init a new project with yarn init
  2. Setup workspaces in package.json
"workspaces": {
    "packages": [
      "packages/*",
      "common/*"
    ],
  },
  1. Create an electron forge app with yarn create electron-app packages/my-app
  2. Create another workspace to use in the electron app
  3. Import the 2nd workspace into the electron app workspace
  4. Build the app yarn workspace my-app make
  5. Run the app

See that it errors out due to a missing dependency such as electron-squirrel-startup.

  1. Add nohoist: "**"
  2. Build the app yarn workspace my-app make

See that it errors out due to symbolic links

Additional information

I enabled nohoist in my project to get around the dependency issue as described in #1377.

Since I'm trying to use another local workspace module in my electron app, thats linked as a symbolic link in node_modules. Electron forge/builder doesn't recognize that it should follow the symbolic link and include that, and instead errors out.

I have no clue at this point how to get this all working. One of the discussions included using an afterCopy hook to run yarn install --production. I believe this would fix not having to use nohoist, but I don't think it would fix the issue of using local workspaces that are symbolically linked together? I've been unable to figure out a hook that works for me.

@easternmotors
Copy link

@jrj2211 I have a similar setup, have you figured out a workaround? If you haven't, I would try using the workspace: protocol instead of using symbolic links. So instead of:

"@scope/other-package": "link:../path/to/other/package"

using

"@scope/other-package": "workspace:*"

Let me know if you are still having issues.

@joezappie
Copy link
Author

joezappie commented Dec 9, 2023

I ended up coming up with a very complicated packageAfterCopy script to manually remove my local workspaces as dependency's and then copy them into the build folder. Feels very jank, so I'd absolutely love to delete that.

I apologize, I do not follow what you're suggesting here as an alternatives. Is that a keyword that can be added in the package.json dependencys?

My root package.json defines my workspaces:

 "workspaces": {
    "packages": [
      "packages/*",
    ]
  },

I then have the following folders:

/packages/electron-app
/packages/server

My electron-app package has a dependency to my server package. I ran npm i server -w electron-app which added the following to my /packages/electron-app/package.json:

  "dependencies": {
    "server": "^1.0.0"
  }

I don't use the link: protocol anywhere, though my understanding is what npm does here is use a symbolic link. Is what your suggesting, putting workspace before the dependency such as:

 "dependencies": {
    "server": "workspace: *"
  }

@joezappie
Copy link
Author

Okay, I just tried this and still not having any luck. Heres a minimal github repository.

test-package workspace installed into electron-app workspace:

  "dependencies": {
    "electron-squirrel-startup": "^1.0.0",
    "test-package": "workspaces: *"
  }

If I run yarn workspace electron-app start it starts up fine.

If i run yarn workspace electron-app make it fails with:

 An unhandled rejection has occurred inside Forge:
Error: EPERM: operation not permitted, symlink 'C:\Users\joeja\projects\yarn-electron-workspaces\packages\test' -> 'C:\Users\joeja\A
ppData\Local\Temp\electron-packager\tmp-CpW04V\resources\app\node_modules\test-package'

I added no-hoist to my root package.json because it was complaining electron-squirrel-startup couldn't be found BUT the app did build without complaining about symbolic links:

 "workspaces": {
    "packages": [
      "packages/*"
    ],
    "nohoist": [
      "**"
    ]
  }

So TLDR:

With no-hoist - app wont even build - symbolic link error
Without no-hoist - node_modules is empty so its missing dependency's such as electron-squirrel-startup.

I cant find a way to satisfy both. Any help is appriciated.

@easternmotors
Copy link

@jrj2211 Thanks for the minimal repo! That definitely helps. I forked your repo and made an MR explaining what I changed and why I changed it. I can run the repo on my machine now and start and make commands from the root dir both work.

Hope this helps and let me know if you run into any issues with that setup. I Typescript-ify and ESM-ify everything I can so the minimal changes might have a bit of that flavor still baked in.

@joezappie
Copy link
Author

Awesome! Just checked it out and I am able to build and run it as well. I can't thank you enough for taking the time to pull my repo, make changes, and then even write explanations for why you changed what you did!! Incredible.

Closing this issue as resolved.

@easternmotors
Copy link

@jrj2211 No problem! I've done my fair share of struggling to get Electron Forge working with my project so happy to help. I actually use the Webpack plugin so it was cool seeing how the Vite plugin worked.

@joezappie
Copy link
Author

If you're considering switching over, I'd highly recommend it. I used to do all my projects in Webpack but man Vite just requires almost no config to get things working so I was watching the issue for months and was on it they day they released it. I don't miss all the webpack plugins I'd have to install to get things to build properly.

Electron also recently introduced ESM support, so now time to struggle through fully removing any trace of CJS in my projects!

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