caoxiemeihao / nuxt-electron

Integrate Nuxt and Electron
MIT License
190 stars 21 forks source link

[Bug] path.join is not a function | use Node.js in Renderer #12

Closed mtdvlpr closed 1 year ago

mtdvlpr commented 1 year ago

Hi, I love your module! Just having a problem getting it all to work. I'm not sure this is a bug on your end, but maybe someone can help me figure this out. I can' use any node modules, like path, fs and os. I'm now getting the following error:

TypeError: path.join is not a function
    at node_modules/electron/index.js (index.js:4:23)
    at __require2 (chunk-TSHM3N6P.js?v=72d195e1:16:50)
    at electron.js?v=72d195e1:6:16
caoxiemeihao commented 1 year ago
  1. npm i -D vite-plugin-electron-renderer

  2. electron/main.ts

  win = new BrowserWindow({
    webPreferences: {
      preload,
+     contextIsolation: false,
+     nodeIntegration: true,
    },
  })
  1. nuxt.config.ts
+ import renderer from 'vite-plugin-electron-renderer'

  export default defineNuxtConfig({
    modules: [
      'nuxt-electron',
    ],
+   vite: {
+     plugins: [
+       renderer({
+         nodeIntegration: true,
+       }),
+     ],
+   },
  })
mtdvlpr commented 1 year ago

That fixed it! Thanks!