fix(kit): log module id to the console when import fails (#8198)

This commit is contained in:
Andrew Mudrov 2022-10-15 15:35:01 +04:00 committed by GitHub
parent 5e7dfc2338
commit ddbfae1bec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,7 +42,13 @@ async function normalizeModule (nuxtModule: string | NuxtModule, inlineOptions?:
const _src = resolveModule(resolveAlias(nuxtModule), { paths: nuxt.options.modulesDir })
// TODO: also check with type: 'module' in closest `package.json`
const isESM = _src.endsWith('.mjs')
try {
nuxtModule = isESM ? await importModule(_src) : requireModule(_src)
} catch (error: unknown) {
console.error(`Error while requiring module \`${nuxtModule}\`: ${error}`)
throw error
}
}
// Throw error if input is not a function