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

Problems building Nuxt 3 on electron startup #27236

Open
sev-b opened this issue May 15, 2024 · 0 comments
Open

Problems building Nuxt 3 on electron startup #27236

sev-b opened this issue May 15, 2024 · 0 comments

Comments

@sev-b
Copy link

sev-b commented May 15, 2024

Environment

- Operating System: Windows_NT
- Node Version:     v20.12.2
- Nuxt Version:     3.11.2
- CLI Version:      3.11.1
- Nitro Version:    2.9.6
- Package Manager:  npm@10.5.0
- Builder:          -
- User Config:      app, modules, ssr, router, build, vite
- Runtime Modules:  @nuxtjs/eslint-module@4.1.0, @pinia/nuxt@0.5.1, ()
- Build Modules:    -

Reproduction

can't share code due to corporate law
if very necessary I will try to create an electron-fiddle

Describe the bug

In my electron app I am using Nuxt and have been migrating from v2 to v3 over the last few days.

Now when calling my builder function in main.js I get the error

TypeError: Cannot read properties of undefined (reading 'map')
 at initNuxt (nuxt/dist/index.mjs:3928:46)

for this

async function readyNuxt() {
  const { createNuxt } = await import('nuxt')
  nuxt = createNuxt(configDev)
  nuxt.hook('build:done', () => {
    const application = express()
    application.use(nuxt.render)
  })
  nuxt.ready()
}

and

TypeError: Cannot read properties of undefined (reading 'flatMap')
at resolveApp (nuxt/dist/index.mjs:4781:28)

for this

async function readyNuxt() {
  const { createNuxt, build } = await import('nuxt')
  nuxt = createNuxt(configDev)
  nuxt.hook('build:done', () => {
    const application = express()
    application.use(nuxt.render)
  })
  build(nuxt)
}

In Nuxt 2 this worked perfectly:

async function readyNuxt() {
  const { Nuxt, Builder } = await import('nuxt')
  nuxt = new Nuxt(configDev)
  const builder = new Builder(nuxt)
  builder.build()
  nuxt.hook('build:done', () => {
    const application = express()
    application.use(nuxt.render)
  })
}

I know that there are libraries like nuxt-electron that take over a lot of the work here but would prefer keeping my own implementation for now.

Additional context

Config used:

// Copyright (c) 2020-2024 Continental AG.
import { defineNuxtConfig } from 'nuxt/config'
import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'

export default defineNuxtConfig({
  app: {
    baseURL: process.env.NODE_ENV === 'development' ? '/' : './',
    head: {
      meta: [
        { charset: 'utf-8' },
        { name: 'viewport', content: 'width=device-width, initial-scale=1' },
        {
          hid: 'description',
          name: 'description',
          content: process.env.npm_package_description || '',
        },
      ],
      link: [{ rel: 'icon', type: 'image/x-icon', href: 'static/favicon.ico' }],
    },
  },
  modules: [
    '@nuxtjs/eslint-module',
    '@pinia/nuxt',
    (_options, nuxt) => {
      nuxt.hooks.hook('vite:extendConfig', (config) => {
        // @ts-expect-error
        config.plugins.push(vuetify({ autoImport: true }))
      })
    },
  ],
  ssr: false,
  router: {
    hashMode: true,
  },
  build: {
    extend(config, { isDev, isClient }) {
      if (isDev) config.mode = 'development'
      else {
        config.mode = 'production'
      }
    },
    transpile: ['vuetify'],
  },
  vite: {
    vue: {
      template: {
        transformAssetUrls,
      },
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `
          @use "./assets/scss/abstracts/_index.scss" as *;
          @use "./assets/scss/main.scss"  as *;
          `,
        },
      },
    },
  },
})

Logs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant