Repository: nuxt/nuxt
File: packages/vite/src/vite-node.ts (TypeScript)

Code before:
}

function createViteNodeApp (ctx: ViteBuildContext, invalidates: Set<string> = new Set()) {
  const app = createApp()

  app.use('/manifest', defineEventHandler(() => {
    const manifest = getManifest(ctx)
    return manifest
  }))

  app.use('/invalidates', defineEventHandler(() => {
    const ids = Array.from(invalidates)
    invalidates.clear()
    return ids
  }))

  app.use('/module', defineLazyEventHandler(() => {
    const viteServer = ctx.ssrServer!
    const node = new ViteNodeServer(viteServer, {
      deps: {
        inline: [
          /^virtual:/,
          /\.ts$/,
          // Rollup
          /\0/,
          // Common
          /^#/,
          /\?/,
        ],
        external: [
          '#shared',
          new RegExp('^' + escapeStringRegexp(withTrailingSlash(resolve(ctx.nuxt.options.rootDir, ctx.nuxt.options.dir.shared)))),
        ],
      },
      transformMode: {
        ssr: [/.*/],
        web: [],
      },
    })

    return eventHandler(async (event) => {
      const moduleId = decodeURI(event.path).substring(1)
      if (moduleId === '/') {
        throw createError({ statusCode: 400 })
      }
      if (isAbsolute(moduleId) && !isFileServingAllowed(moduleId, viteServer)) {
        throw createError({ statusCode: 403 /* Restricted */ })
      }
      const module = await node.fetchModule(moduleId).catch(async (err) => {
        const errorData = {
          code: 'VITE_ERROR',

Review comment (suggestion):
we can drop this as it's already set on `ssr.noExternal` here:

https://github.com/nuxt/nuxt/blob/a01c41b4d3db216aa48909aa29334c68bcff6e9a/packages/vite/src/server.ts#L67-L73

and this seems to be respected by `vite-node` when creating the server:

https://github.com/vitest-dev/vitest/blob/bf7b36ac1054fd80a54d393448e8fc25eec153c1/packages/vite-node/src/server.ts#L76-L95

Code after:
}

function createViteNodeApp (ctx: ViteBuildContext, invalidates: Set<string> = new Set()) {
  const app = createApp()

  app.use('/manifest', defineEventHandler(() => {
    const manifest = getManifest(ctx)
    return manifest
  }))

  app.use('/invalidates', defineEventHandler(() => {
    const ids = Array.from(invalidates)
    invalidates.clear()
    return ids
  }))

  app.use('/module', defineLazyEventHandler(() => {
    const viteServer = ctx.ssrServer!
    const node = new ViteNodeServer(viteServer, {
      deps: {
        inline: [
          // Common
          /^#/,
          /\?/,
        ],
        external: [
          '#shared',
          new RegExp('^' + escapeStringRegexp(withTrailingSlash(resolve(ctx.nuxt.options.rootDir, ctx.nuxt.options.dir.shared)))),
        ],
      },
      transformMode: {
        ssr: [/.*/],
        web: [],
      },
    })

    return eventHandler(async (event) => {
      const moduleId = decodeURI(event.path).substring(1)
      if (moduleId === '/') {
        throw createError({ statusCode: 400 })
      }
      if (isAbsolute(moduleId) && !isFileServingAllowed(moduleId, viteServer)) {
        throw createError({ statusCode: 403 /* Restricted */ })
      }
      const module = await node.fetchModule(moduleId).catch(async (err) => {
        const errorData = {
          code: 'VITE_ERROR',
          id: moduleId,
          stack: '',
          ...err,
        }