mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 00:23:53 +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(() => {
|
app.use('/module', defineLazyEventHandler(() => {
|
||||||
const viteServer = ctx.ssrServer!
|
const viteServer = ctx.ssrServer!
|
||||||
const node: ViteNodeServer = new ViteNodeServer(viteServer, {
|
const node = new ViteNodeServer(viteServer, {
|
||||||
deps: {
|
deps: {
|
||||||
inline: [
|
inline: [
|
||||||
/\/node_modules\/(.*\/)?(nuxt|nuxt3|nuxt-nightly)\//,
|
/\/node_modules\/(.*\/)?(nuxt|nuxt3|nuxt-nightly)\//,
|
||||||
@ -139,6 +139,7 @@ function createViteNodeApp (ctx: ViteBuildContext, invalidates: Set<string> = ne
|
|||||||
web: [],
|
web: [],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const isExternal = createIsExternal(viteServer, ctx.nuxt.options.rootDir, ctx.nuxt.options.modulesDir)
|
const isExternal = createIsExternal(viteServer, ctx.nuxt.options.rootDir, ctx.nuxt.options.modulesDir)
|
||||||
node.shouldExternalize = async (id: string) => {
|
node.shouldExternalize = async (id: string) => {
|
||||||
const result = await isExternal(id)
|
const result = await isExternal(id)
|
||||||
@ -156,13 +157,17 @@ function createViteNodeApp (ctx: ViteBuildContext, invalidates: Set<string> = ne
|
|||||||
if (isAbsolute(moduleId) && !isFileServingAllowed(moduleId, viteServer)) {
|
if (isAbsolute(moduleId) && !isFileServingAllowed(moduleId, viteServer)) {
|
||||||
throw createError({ statusCode: 403 /* Restricted */ })
|
throw createError({ statusCode: 403 /* Restricted */ })
|
||||||
}
|
}
|
||||||
const module = await node.fetchModule(moduleId).catch((err) => {
|
const module = await node.fetchModule(moduleId).catch(async (err) => {
|
||||||
const errorData = {
|
const errorData = {
|
||||||
code: 'VITE_ERROR',
|
code: 'VITE_ERROR',
|
||||||
id: moduleId,
|
id: moduleId,
|
||||||
stack: '',
|
stack: '',
|
||||||
...err,
|
...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 })
|
throw createError({ data: errorData })
|
||||||
})
|
})
|
||||||
return module
|
return module
|
||||||
|
Loading…
Reference in New Issue
Block a user