mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-22 16:39:58 +00:00
fix(kit): expose module dependency errors (#31035)
This commit is contained in:
parent
d992c0da95
commit
bb1a376558
@ -85,6 +85,8 @@ export const normalizeModuleTranspilePath = (p: string) => {
|
||||
return getDirectory(p).split('node_modules/').pop() as string
|
||||
}
|
||||
|
||||
const MissingModuleMatcher = /Cannot find module\s+['"]?([^'")\s]+)['"]?/i
|
||||
|
||||
export async function loadNuxtModuleInstance (nuxtModule: string | NuxtModule, nuxt: Nuxt = useNuxt()) {
|
||||
let buildTimeModuleMeta: ModuleMeta = {}
|
||||
let resolvedModulePath: string | undefined
|
||||
@ -124,9 +126,17 @@ export async function loadNuxtModuleInstance (nuxtModule: string | NuxtModule, n
|
||||
break
|
||||
} catch (error: unknown) {
|
||||
const code = (error as Error & { code?: string }).code
|
||||
if (code === 'MODULE_NOT_FOUND' || code === 'ERR_PACKAGE_PATH_NOT_EXPORTED' || code === 'ERR_MODULE_NOT_FOUND' || code === 'ERR_UNSUPPORTED_DIR_IMPORT' || code === 'ENOTDIR') {
|
||||
if (code === 'ERR_PACKAGE_PATH_NOT_EXPORTED' || code === 'ERR_UNSUPPORTED_DIR_IMPORT' || code === 'ENOTDIR') {
|
||||
continue
|
||||
}
|
||||
if (code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND') {
|
||||
const module = MissingModuleMatcher.exec((error as Error).message)?.[1]
|
||||
// verify that it's missing the nuxt module otherwise it may be a sub dependency of the module itself
|
||||
// i.e module is importing a module that is missing
|
||||
if (!module || module.includes(nuxtModule as string)) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
logger.error(`Error while importing module \`${nuxtModule}\`: ${error}`)
|
||||
throw error
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user