mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(vite): add transformation result to log for parse errors (#28508)
This commit is contained in:
parent
c4cad445ea
commit
fefe4e5c8d
@ -126,7 +126,7 @@ function createViteNodeApp (ctx: ViteBuildContext, invalidates: Set<string> = ne
|
||||
|
||||
app.use('/module', defineLazyEventHandler(() => {
|
||||
const viteServer = ctx.ssrServer!
|
||||
const node: ViteNodeServer = new ViteNodeServer(viteServer, {
|
||||
const node = new ViteNodeServer(viteServer, {
|
||||
deps: {
|
||||
inline: [
|
||||
/\/node_modules\/(.*\/)?(nuxt|nuxt3|nuxt-nightly)\//,
|
||||
@ -139,6 +139,7 @@ function createViteNodeApp (ctx: ViteBuildContext, invalidates: Set<string> = ne
|
||||
web: [],
|
||||
},
|
||||
})
|
||||
|
||||
const isExternal = createIsExternal(viteServer, ctx.nuxt.options.rootDir, ctx.nuxt.options.modulesDir)
|
||||
node.shouldExternalize = async (id: string) => {
|
||||
const result = await isExternal(id)
|
||||
@ -156,13 +157,17 @@ function createViteNodeApp (ctx: ViteBuildContext, invalidates: Set<string> = ne
|
||||
if (isAbsolute(moduleId) && !isFileServingAllowed(moduleId, viteServer)) {
|
||||
throw createError({ statusCode: 403 /* Restricted */ })
|
||||
}
|
||||
const module = await node.fetchModule(moduleId).catch((err) => {
|
||||
const module = await node.fetchModule(moduleId).catch(async (err) => {
|
||||
const errorData = {
|
||||
code: 'VITE_ERROR',
|
||||
id: moduleId,
|
||||
stack: '',
|
||||
...err,
|
||||
}
|
||||
|
||||
if (!errorData.frame && errorData.code === 'PARSE_ERROR') {
|
||||
errorData.frame = await node.transformModule(moduleId, 'web').then(({ code }) => `${err.message || ''}\n${code}`).catch(() => undefined)
|
||||
}
|
||||
throw createError({ data: errorData })
|
||||
})
|
||||
return module
|
||||
|
Loading…
Reference in New Issue
Block a user