electron-vite icon indicating copy to clipboard operation
electron-vite copied to clipboard

Issues with yarn workspaces / monorepo

Open apss-pohl opened this issue 1 year ago • 6 comments

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:

  • i don't get any console or application logs -- e.g. https://github.com/apss-pohl/nestjs-test/blob/feat/ev/apps/main/src/main.ts#L47) -- other nestjs output

~~- 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 avatar Jul 28 '23 14:07 apss-pohl

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)

apss-pohl avatar Jul 28 '23 14:07 apss-pohl

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

alex8088 avatar Jul 30 '23 10:07 alex8088

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 "

apss-pohl avatar Jul 31 '23 06:07 apss-pohl

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

nodeLinker: "node-modules"

alex8088 avatar Jul 31 '23 06:07 alex8088

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 avatar Jul 31 '23 06:07 apss-pohl

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

apss-pohl avatar Aug 31 '23 11:08 apss-pohl