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

Issues with yarn workspaces / monorepo #237

Open
4 tasks done
apss-pohl opened this issue Jul 28, 2023 · 6 comments
Open
4 tasks done

Issues with yarn workspaces / monorepo #237

apss-pohl opened this issue Jul 28, 2023 · 6 comments

Comments

@apss-pohl
Copy link

apss-pohl commented Jul 28, 2023

Describe the bug

I am currently trying to implement an existing monorepo structure which makes use of yarn workspaces to your bundler because i think you really did an awsome job here! Big praise!

For testing purpose i created a reduced repository:
https://github.com/apss-pohl/nestjs-test/tree/feat/ev

There are some issues i am currently facing:

- the renderer cant be changed, i have to provide src/renderer
https://github.com/apss-pohl/nestjs-test/blob/feat/ev/apps/main/src/main.ts#L53

index.html file is not found in /src/renderer directory
dep-3b8eb186.js:12907
error during start dev server and electron app:
Error: build rollupOptions input field required for the electron vite renderer config

UPDATE/ RESOLVED: Overlooked the note here: https://electron-vite.org/guide/dev.html#customizing

  • something is off with the bundling, the external packages cannot be found (biggest issue)
App threw an error during load
main.js:124
Error: Cannot find module '@nestjs/websockets/socket-module'

I played a lot with the externalization of those but i dont get it working (this did the trick in my current bundler):
https://github.com/apss-pohl/nestjs-test/blob/feat/ev/electron.vite.config.ts#L36
If i don't add those to the list of external i get following output:

"class-transformer/storage" is imported by "class-transformer/storage?commonjs-external", but could not be resolved  treating it as an external dependency.

Any advice highly appreciated

Electron-Vite Version

1.0.25

Electron Version

^24.6.2

Vite Version

^4.4.2

Validations

@apss-pohl
Copy link
Author

apss-pohl commented Jul 28, 2023

I also created a branch with nestjs but without the workspaces:
https://github.com/apss-pohl/nestjs-test/tree/feat/ev_plain
This is working as expected (First two point are the same)

@alex8088
Copy link
Owner

Bad config https://github.com/apss-pohl/nestjs-test/blob/feat/ev/electron.vite.config.ts

Simple way:

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin(), swcPlugin()],
    build: {
      rollupOptions: {
        input: {
          index: resolve(__dirname, 'apps/main/index.ts')
        }
      }
    }
  },
  preload: {
    plugins: [externalizeDepsPlugin()],
    build: {
      rollupOptions: {
        input: {
          index: resolve(__dirname, 'apps/preload/index.ts')
        }
      }
    }
  },
  renderer: {
    root: './apps/renderer'
    build: {
      rollupOptions: {
        input: {
          resolve(__dirname, 'apps/renderer/index.html')
        }
      }
    }
  }
}

About dependencies:
Check out https://electron-vite.org/guide/dev.html#dependencies-vs-devdependencies

@apss-pohl
Copy link
Author

Hello,
thank you for your reply. I changed the configuration following your recommendations: https://github.com/apss-pohl/nestjs-test/blob/feat/ev/electron.vite.config.ts
But it makes no difference (The issue mentioned with the renderer was already fixed).
I was also reading the dependencies section carefully again but i cant get it up and running. I picked '@nestjs/websockets/socket-module' as example because it is the first one breaking. I literaly treid every combination: Configured it as external dependecy within your plugin, excluded it, included it, configured it external within rollup section. And also as manual chunk:

vite v4.4.7 building for development...
dep-3b8eb186.js:12907
transforming...
dep-3b8eb186.js:12907
"@nestjs/websockets/socket-module" is imported by "�@nestjs/websockets/socket-module?commonjs-external", but could not be resolved  treating it as an external dependency.
node-entry.js:24103
"@nestjs/microservices/microservices-module" is imported by "�@nestjs/microservices/microservices-module?commonjs-external", but could not be resolved  treating it as an external dependency.
node-entry.js:24103
"class-transformer/storage" is imported by "�class-transformer/storage?commonjs-external", but could not be resolved  treating it as an external dependency.
node-entry.js:24103
 2342 modules transformed.
dep-3b8eb186.js:12907
rendering chunks...
dep-3b8eb186.js:12907
out/main/chunks/@nestjs/websockets/socket-module-be58e914.js      0.11 kB  map:     0.11 kB
dep-3b8eb186.js:12907
out/main/index.js                                             3,779.43 kB  map: 6,343.23 kB
dep-3b8eb186.js:12907
 built in 11.85s
dep-3b8eb186.js:12907

build the electron main process successfully
publicUtils.cjs:3869

-----

publicUtils.cjs:3869
vite v4.4.7 building for development...
dep-3b8eb186.js:12907
transforming...
dep-3b8eb186.js:12907
 1 modules transformed.
dep-3b8eb186.js:12907
rendering chunks...
dep-3b8eb186.js:12907
out/preload/index.js  0.45 kB  map: 1.01 kB
dep-3b8eb186.js:12907
 built in 53ms
dep-3b8eb186.js:12907

build the electron preload files successfully
publicUtils.cjs:3869

-----

publicUtils.cjs:3869
dev server running for the electron renderer process at:

dep-3b8eb186.js:12907Local:   http://localhost:5173/
dep-3b8eb186.js:12907Network: use --host to expose
dep-3b8eb186.js:12907

start electron app...

publicUtils.cjs:3869
App threw an error during load
main.js:124
Error: Cannot find module '@nestjs/websockets/socket-module'            // <------------------------ The issue
Require stack:

I think the bundling gets confused with the workspaces. It does work with this very simple config and workspaces removed, no special dependency configuration needed at all (but has the same depedencies):
https://github.com/apss-pohl/nestjs-test/blob/feat/ev_plain/electron.vite.config.ts

Startup:

vite v4.4.7 building for development...
dep-3b8eb186.js:12907
transforming...
dep-3b8eb186.js:12907
 5 modules transformed.
dep-3b8eb186.js:12907
rendering chunks...
dep-3b8eb186.js:12907
out/main/index.js  7.15 kB  map: 10.77 kB
dep-3b8eb186.js:12907
 built in 176ms
dep-3b8eb186.js:12907

build the electron main process successfully
publicUtils.cjs:3869

-----

publicUtils.cjs:3869
vite v4.4.7 building for development...
dep-3b8eb186.js:12907
transforming...
dep-3b8eb186.js:12907
 1 modules transformed.
dep-3b8eb186.js:12907
rendering chunks...
dep-3b8eb186.js:12907
out/preload/index.js  0.48 kB  map: 1.29 kB
dep-3b8eb186.js:12907
 built in 18ms
dep-3b8eb186.js:12907

build the electron preload files successfully
publicUtils.cjs:3869

-----

publicUtils.cjs:3869
dev server running for the electron renderer process at:

dep-3b8eb186.js:12907Local:   http://localhost:5173/
dep-3b8eb186.js:12907Network: use --host to expose
dep-3b8eb186.js:12907

start electron app...

publicUtils.cjs:3869
123123

@alex8088
Copy link
Owner

Yarn 3, add configuration in the .yarnrc as follows:

nodeLinker: "node-modules"

@apss-pohl
Copy link
Author

Yarn 3, add configuration in the .yarnrc as follows:

nodeLinker: "node-modules"

This is already the case: https://github.com/apss-pohl/nestjs-test/blob/feat/ev/.yarnrc.yml

@apss-pohl
Copy link
Author

I cant get past this. Is there any other idea what i can try?

@alex8088 alex8088 closed this as completed Mar 3, 2024
@alex8088 alex8088 reopened this Mar 3, 2024
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