nuxt
nuxt copied to clipboard
Problems building Nuxt 3 on electron startup
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: [email protected]
- Builder: -
- User Config: app, modules, ssr, router, build, vite
- Runtime Modules: @nuxtjs/[email protected], @pinia/[email protected], ()
- 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