fix: resolve @nuxt/kit module import error in browser
All checks were successful
deploy-analiticaNucleo / deploy (push) Successful in 36s

- Replace external module references with empty stub file
- Add .nuxt-stubs/empty.mjs to provide browser-compatible module
- Update workaround to resolve server-only modules to stub file instead of marking as external
This commit is contained in:
2025-10-05 12:43:01 -06:00
parent da3b08f050
commit 8df579e36a
2 changed files with 28 additions and 13 deletions

View File

@@ -0,0 +1 @@
export default {}

View File

@@ -2,29 +2,43 @@
// This is a temporary fix until @nuxt/ui properly handles ssr: false
import type { Plugin } from 'vite'
import { fileURLToPath } from 'url'
import { dirname, resolve } from 'path'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const emptyModulePath = resolve(__dirname, '.nuxt-stubs/empty.mjs')
export function disableImportProtection(): Plugin {
return {
name: 'disable-import-protection-for-nuxt-ui',
enforce: 'pre',
resolveId(id, importer) {
// External node binary files
if (id.endsWith('.node')) {
return { id, external: true }
}
// Server-only packages that should be stubbed for client bundle
const serverPackages = [
'@nuxt/kit',
'@tailwindcss/node',
'@tailwindcss/oxide',
'jiti'
]
// External Node.js built-in modules
const nodeModules = ['fs', 'path', 'url', 'fs/promises', 'node:url', 'node:module', 'node:fs', 'node:path']
if (nodeModules.includes(id) || id.startsWith('node:')) {
return { id, external: true }
}
// External server-only packages from @nuxt/ui imports
const serverPackages = ['@nuxt/kit', '@tailwindcss/node', '@tailwindcss/oxide', 'jiti']
for (const pkg of serverPackages) {
if (id === pkg || id.startsWith(pkg + '/')) {
return { id, external: true }
}
return emptyModulePath
}
}
// Stub .node binary files
if (id.endsWith('.node')) {
return emptyModulePath
}
// Stub Node.js built-in modules for client bundle
const nodeModules = ['fs', 'path', 'url', 'fs/promises']
const nodePrefix = ['node:url', 'node:module', 'node:fs', 'node:path']
if (nodeModules.includes(id) || nodePrefix.includes(id) || id.startsWith('node:')) {
return emptyModulePath
}
}
}