mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-23 00:50:05 +00:00
fix(kit): expose module dependency errors (#31035)
This commit is contained in:
parent
15cf4d7466
commit
5fa257ad81
@ -79,6 +79,8 @@ export const normalizeModuleTranspilePath = (p: string) => {
|
|||||||
return getDirectory(p).split('node_modules/').pop() as 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()) {
|
export async function loadNuxtModuleInstance (nuxtModule: string | NuxtModule, nuxt: Nuxt = useNuxt()) {
|
||||||
let buildTimeModuleMeta: ModuleMeta = {}
|
let buildTimeModuleMeta: ModuleMeta = {}
|
||||||
let resolvedModulePath: string | undefined
|
let resolvedModulePath: string | undefined
|
||||||
@ -118,9 +120,17 @@ export async function loadNuxtModuleInstance (nuxtModule: string | NuxtModule, n
|
|||||||
break
|
break
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const code = (error as Error & { code?: string }).code
|
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
|
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}`)
|
logger.error(`Error while importing module \`${nuxtModule}\`: ${error}`)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user