import { Ct as useNuxt, Dt as DEFAULT_JSX_FILE_EXTENSIONS, E as loadJiti, Et as reporters, G as directoryToURL, M as buildDiagnostics, Ot as DEFAULT_JS_FILE_EXTENSIONS, Tt as docsBase, _t as readPackageJSON, b as installModules, ft as parseNodeModulePath, i as componentDiagnostics, j as configDiagnostics, k as findPackageMissingSubpath, m as kUnusedVariants, n as pageDiagnostics, p as kServerApi, r as resolveModuleExportNames, t as pluginDiagnostics } from "../plugins-DPmL7lze.mjs"; import { defineDiagnostics } from "nostics"; import process from "node:process"; import { isAbsolute, join, resolve } from "pathe"; import { resolveModulePath } from "exsolve"; //#region src/diagnostics/head.ts /** * B6xxx * Head / auto-import diagnostics. * * @internal */ const headDiagnostics = /* #__PURE__ */ defineDiagnostics({ docsBase, reporters, codes: { NUXT_B6001: { why: (p) => `\`${p.file}\` imports head composables directly from \`${p.module}\`, which loses Nuxt's type safety.`, fix: "Import from `#imports` instead.", docs: false }, NUXT_B6002: { why: (p) => `\`${p.name}\` is already auto-imported by Nuxt as a built-in, and overriding it will likely cause issues.`, fix: (p) => `Rename \`${p.name}\` in \`${p.file}\` so it no longer collides with the built-in auto-import.`, docs: false }, NUXT_B6003: { why: "`unhead.legacy` is deprecated and will be removed.", fix: "Remove deprecated head patterns (`hid`, `vmid`, `children`, `body: true`) and resolve promise values before passing them to `useHead`.", docs: false }, NUXT_B6004: { why: "`experimental.headNext` is deprecated. CAPO sorting is now the default.", fix: "Remove `experimental.headNext` from your `nuxt.config`, or set `unhead.legacy: true` to opt out temporarily.", docs: false }, NUXT_B6005: { why: (p) => `Could not resolve \`${p.from}\` used by the auto-import \`${p.name}\`.`, fix: "Check the `from` path in `imports.presets` (or the module that registered this import). Auto-imports from an unresolvable module are silently skipped and can surface as unrelated type errors elsewhere.", docs: false } } }); //#endregion //#region src/diagnostics/bundler.ts /** * B7xxx * Bundler (Vite / webpack / Nitro) diagnostics. * * @internal */ const bundlerDiagnostics = /* #__PURE__ */ defineDiagnostics({ docsBase, reporters, codes: { NUXT_B7001: { why: "`rollup-plugin-visualizer` is not installed, so bundle analysis cannot run.", fix: (p) => `Run \`${p.installCommand}\` to enable bundle analysis.`, docs: false }, NUXT_B7002: { why: (p) => `Some \`vite.optimizeDeps.include\` entries could not be resolved: ${p.deps}.`, fix: "Remove or correct these entries in the `vite.optimizeDeps.include` array of your `nuxt.config.ts`. Report entries added by a Nuxt module to the module author.", docs: false }, NUXT_B7003: { why: "The server-side bundle produced more than one JS entry file.", fix: "Avoid using `optimization.splitChunks` in the server config.", docs: false }, NUXT_B7004: { why: (p) => `Webpack entry \`${p.entryName}\` was not found.`, fix: (p) => `Check that the \`entry\` option in your webpack configuration points to an existing file. Expected entry name: \`${p.entryName}\`.`, docs: false }, NUXT_B7005: { why: (p) => `No client entry was found in \`rollupOptions.input\`; expected an \`entry\` key or a string input but received ${p.input}.`, fix: "Set `vite.build.rollupOptions.input` to a string or an object with an `entry` key in your `nuxt.config`.", docs: false }, NUXT_B7006: { why: (p) => `No server entry was found in \`rollupOptions.input\`; expected a \`server\` key or a string input but received ${p.input}.`, fix: "Set `vite.build.rollupOptions.input` to a string or an object with a `server` key in your `nuxt.config`.", docs: false }, NUXT_B7007: { why: (p) => `The PostCSS plugin \`${p.pluginName}\` could not be loaded.`, fix: (p) => `Run \`${p.installCommand}\` to install the PostCSS plugin.`, docs: false }, NUXT_B7008: { why: "`@vitejs/plugin-vue-jsx` is not installed, so JSX support is unavailable.", fix: (p) => `Run \`${p.installCommand}\` to install it.`, docs: false }, NUXT_B7009: { why: (p) => `The Babel dependencies required for decorator support are missing: ${p.deps}.`, fix: (p) => `Run \`${p.installCommand}\` to install the required Babel decorator dependencies.`, docs: false }, NUXT_B7011: { why: (p) => `The PostCSS plugin \`${p.pluginName}\` could not be imported, which is unexpected.`, fix: (p) => `Run \`${p.installCommand}\` to install it, or report this issue at https://github.com/nuxt/nuxt/issues.`, docs: false }, NUXT_B7012: { why: (p) => `A ViteNode socket payload of ${p.requiredSize} bytes exceeds the internal buffer limit of ${p.maxSize} bytes.`, fix: "Reduce the payload size sent through the ViteNode socket.", docs: false }, NUXT_B7013: { why: "The ViteNode socket server was started without a configured socket path.", fix: "This is likely an internal Nuxt bug. Please report it at https://github.com/nuxt/nuxt/issues.", docs: false }, NUXT_B7014: { why: (p) => `The webpack \`${p.name}\` build failed with errors.`, fix: "Fix the build errors listed above. If the errors are unclear, try running `nuxt cleanup` and rebuilding.", docs: false }, NUXT_B7015: { why: "Payload extraction is disabled, which is suboptimal for full-static output.", fix: "Set `experimental.payloadExtraction` to `true` or `'client'`.", docs: false }, NUXT_B7016: { why: (p) => `The configured \`spaLoadingTemplate\` path does not exist: \`${p.path}\`.`, fix: "Point `spaLoadingTemplate` in `nuxt.config` at an existing HTML file, or set it to `true` to use the default template.", docs: false }, NUXT_B7017: { why: "Could not find the Nuxt dev server to attach Rspack HMR to; hot module replacement will be disabled.", fix: "This is likely an internal Nuxt bug. Please report it with a reproduction.", docs: false }, NUXT_B7018: { why: "Failed to restrict vite-node socket permissions; closing the socket.", fix: "Check that the temporary directory used for the vite-node socket is writable and supports `chmod`.", docs: false }, NUXT_B7019: { why: "The server webpack build does not externalize dependencies.", fix: "Externalize dependencies in the server build (`externals`) for better build performance.", docs: false }, NUXT_B7020: { why: "The client build manifest is disabled, but Nuxt requires it to render the correct assets for each route.", fix: "Remove any `build.manifest: false` override from your `nuxt.config` `vite` options or from a Vite plugin `config`/`configEnvironment` hook.", docs: false }, NUXT_B7021: { why: (p) => `The client build manifest was expected at \`${p.manifestFile}\` but was not emitted by the client build.`, fix: "Check that no Vite plugin removes or renames the client build manifest in a `generateBundle`/`writeBundle` hook. If this happens with no such plugin, please report it at https://github.com/nuxt/nuxt/issues.", docs: false }, NUXT_B7022: { why: (p) => `Route rules for \`${p.existing}\` and \`${p.route}\` resolve to the same path; \`${p.route}\` takes precedence.`, fix: (p) => `Disambiguate the keys${p.canFold ? " or set `router.options.sensitive: true`" : ""}.`, docs: false }, NUXT_B7023: { why: (p) => `A configured \`nitro.publicAssets\` directory does not exist: \`${p.dir}\`. Requests to \`${p.baseURL}\` will return a 404.`, fix: (p) => `Relative \`dir\` values are resolved against ${p.resolvedFrom}. Point \`dir\` at an existing directory, using an absolute path or a Nuxt alias (such as \`~~/public/video\`) if it lives elsewhere.`, docs: false }, NUXT_B7024: { why: (p) => `The client build output directory is set to \`${p.outDir}\`, but the server builder writes the client build to \`${p.publicDir}\`, so the override is ignored.`, fix: "Remove the `vite.$client.build.outDir` override from your `nuxt.config`, and set `nitro.output.publicDir` to move the whole public output instead.", docs: false }, NUXT_B7025: { why: (p) => `The client build input is set to \`${p.input}\`, which cannot carry the document the server builder emits, so the override is ignored.`, fix: "Pass an object to `vite.$client.build.rolldownOptions.input` if you need additional inputs, or add an `index.html` at the root of your app directory to take over the document itself.", docs: false }, NUXT_B7026: { why: (p) => `The route rule for \`${p.route}\` sets \`redirect.statusCode\`, which the server builder no longer reads.`, fix: "Rename it to `redirect.status`. Nuxt has applied it as `status` for now.", docs: false }, NUXT_B7027: { why: (p) => `The PostCSS plugin \`${p.pluginName}\` could not be loaded: \`${p.packageName}\` is installed but does not provide it.`, fix: (p) => `Remove \`${p.pluginName}\` from \`postcss.plugins\` in your \`nuxt.config\` (or report it to the author of the module that adds it), or install a version of \`${p.packageName}\` that provides it.`, docs: false } } }); //#endregion //#region src/internal/pending-templates.ts const pending = /* @__PURE__ */ new Map(); /** @internal */ function reportPendingTemplates() { if (pending.size === 0) return false; const filenames = [...new Set(pending.values())]; buildDiagnostics.NUXT_B1022({ count: filenames.length, templates: filenames.map((filename) => `\`${filename}\``).join("\n - ") }, { method: "error" }); process.exitCode ||= 1; return true; } process.on("beforeExit", reportPendingTemplates); /** * Nothing else keeps the event loop alive during a build, so a template whose contents never * resolve would otherwise let the process drain and exit 0 with no output. * * @internal */ async function trackPendingTemplate(filename, getContents) { const token = Symbol(filename); pending.set(token, filename); try { return await getContents(); } finally { pending.delete(token); } } //#endregion //#region src/internal/subpath-imports.ts const NODE_MODULES_RE = /node_modules[\\/](?!\.virtual)/; /** * Whether `id` belongs to a package installed in `node_modules` or outside `rootDir` that maps * `specifier` through its own `imports` field. */ async function hasOwnSubpathImport(id, specifier, rootDir) { if (!isAbsolute(id) || !NODE_MODULES_RE.test(id) && id.includes(rootDir.replace(/\/?$/, "/"))) return false; const pkg = await readPackageJSON(id).catch(() => void 0); return Object.keys(pkg?.imports || {}).some((key) => key.includes(specifier)); } //#endregion //#region src/internal/server-build.ts /** * Describe the build the configured server builder produces. See {@link NuxtServerBuild}. * * Called by server builders, once they know their own output paths and target, and by app * builders for the `input` paths they emit; anything else should read the description with * {@link useServerBuild}. * * @internal */ function setServerBuild(build, nuxt = useNuxt()) { const { input, output, capabilities, ...rest } = build; Object.assign(nuxt.serverBuild, rest); Object.assign(nuxt.serverBuild.input, input); Object.assign(nuxt.serverBuild.output, output); Object.assign(nuxt.serverBuild.capabilities, capabilities); } /** * A description of the build the configured server builder produces. * * Paths and the deploy target are resolved on access, so call them from a hook that runs * after the server builder has initialised. * * @internal */ function useServerBuild(nuxt = useNuxt()) { return nuxt.serverBuild ??= createServerBuild(nuxt.options); } /** * The description a Nitro-backed build has before any builder registers its own, and the * fallback for a partially constructed `Nuxt` (a test fixture, say). Every path is * resolved on access, so constructing this never touches the filesystem or requires a * fully resolved configuration. * * @internal */ function createServerBuild(options) { const outputDir = () => options.nitro?.output?.dir || ".output"; const serverDir = () => join(options.buildDir, "dist/server"); const clientDir = () => join(options.buildDir, "dist/client"); return { name: typeof options.server?.builder === "string" ? options.server.builder : "custom", buildsSeparately: !options.experimental?.nitroViteEnvironment, input: { serverEntry: () => join(serverDir(), "server.mjs"), serverDir, clientDir, clientManifest: () => join(clientDir(), ".vite/manifest.json") }, output: { root: () => options.rootDir, dir: () => resolve(options.rootDir, outputDir()), publicDir: () => resolve(options.rootDir, options.nitro?.output?.publicDir || join(outputDir(), "public")) }, capabilities: { server: true, dev: true }, runtime: options._nitroMajor === 3 ? { fetch: "nitro", runtimeConfig: "nitro/runtime-config" } : { runtimeConfig: "nitropack/runtime" } }; } //#endregion //#region src/internal/renderer.ts /** Specifier the SSR renderer reads its build-time configuration from. */ const RENDERER_CONFIG_SPECIFIER = "nuxt/internal/renderer-config"; /** Specifier a server builder imports `createNuxtRenderer` from. */ const RENDERER_SPECIFIER = "nuxt/internal/renderer"; /** The portable server surface, whose implementations the configured server builder supplies. */ const SERVER_SPECIFIER = "nuxt/server"; /** Specifier the shipped `nuxt/server` implementations read runtime configuration from. */ const SERVER_RUNTIME_CONFIG_SPECIFIER = "nuxt/internal/server-runtime-config"; /** Specifier the shipped `nuxt/server` implementations read the app config from. */ const SERVER_APP_CONFIG_SPECIFIER = "nuxt/internal/server-app-config"; /** Dev-only error reporting, empty outside development. */ const DEV_ERROR_SPECIFIER = "nuxt/internal/dev-error"; /** The part of the app config template only the Vue app runs. */ const APP_CONFIG_CLIENT_RE = /\/\*\* client \*\*\/[\s\S]*\/\*\* client-end \*\*\//; /** The specifier the renderer imports each build artifact through, and the {@link NuxtBuildOutputs} key that provides it. */ const BUILD_OUTPUT_SPECIFIERS = { "nuxt/internal/entry": "serverEntry", "nuxt/internal/manifest": "clientManifest", "nuxt/internal/precomputed": "clientPrecomputed", "nuxt/internal/styles": "ssrStyles", "nuxt/internal/entry-chunk": "entryChunkName", "nuxt/internal/entry-ids": "entryIds" }; /** * Generate the body of the `nuxt/internal/renderer-config` module the SSR renderer imports its * build-time configuration from. * * Everything derivable from `nuxt.options` is inlined; the rest defaults to the value of a * build without the feature and is replaced through `overrides`. * * @internal */ function getRendererConfig(options = {}, nuxt = useNuxt()) { const app = nuxt.options.app; const noScripts = nuxt.options.features.noScripts; const payloadExtraction = nuxt.options.experimental.payloadExtraction; const streaming = nuxt.options.experimental.ssrStreaming; const streamingEnabled = typeof streaming === "object" && !!streaming.enabled; const values = { NUXT_NO_SSR: String(nuxt.options.ssr === false), NUXT_PRERENDER_ERROR_PAGES: "[]", NUXT_PRERENDER_NO_SSR_ROUTES: "[]", NUXT_EARLY_HINTS: String(nuxt.options.experimental.writeEarlyHints !== false), NUXT_NO_SCRIPTS: String(noScripts === "all" || !!noScripts && !nuxt.options.dev), NUXT_HAS_NO_SCRIPTS_ROUTES: "false", NUXT_NO_SCRIPTS_PROD: String(noScripts === "production"), NUXT_INLINE_STYLES: String(!!nuxt.options.features.inlineStyles), NUXT_VIEW_TRANSITIONS: String(!!(app.viewTransition && typeof app.viewTransition === "object" && app.viewTransition.enabled)), NUXT_NO_SCRIPTS_PATTERNS: "[]", NUXT_PAGE_PATTERNS: "[]", NUXT_EARLY_404: "false", NUXT_PAGE_MATCHER: "undefined", NUXT_INLINE_ERROR_RENDERING: String(!!nuxt.options.experimental.inlineErrorRendering), PARSE_ERROR_DATA: String(!!nuxt.options.experimental.parseErrorData), NUXT_JSON_PAYLOADS: String(!!nuxt.options.experimental.renderJsonPayloads), NUXT_PAYLOAD_EXTRACTION: String(payloadExtraction !== false), NUXT_PAYLOAD_INLINE: String(payloadExtraction !== true), NUXT_RUNTIME_PAYLOAD_EXTRACTION: "false", NUXT_SSR_STREAMING: String(streamingEnabled), NUXT_SSR_STREAMING_BOT_RE: streamingEnabled && streaming.botRegex instanceof RegExp ? String(streaming.botRegex) : "/^$/", appHead: JSON.stringify(app.head), appRootTag: JSON.stringify(app.rootTag), appRootAttrs: JSON.stringify(app.rootAttrs), appTeleportTag: JSON.stringify(app.teleportTag), appTeleportAttrs: JSON.stringify(app.teleportAttrs), appSpaLoaderTag: JSON.stringify(app.spaLoaderTag), appSpaLoaderAttrs: JSON.stringify(app.spaLoaderAttrs), spaLoadingTemplateOutside: String(nuxt.options.experimental.spaLoadingTemplateLocation === "body"), spaTemplate: "\"\"", appId: JSON.stringify(nuxt.options.appId), multiApp: String(!!nuxt.options.future.multiApp), componentIslands: "false", componentIslandsActive: "false", tracingChannelNuxt: String(!!(nuxt.options.tracingChannel && typeof nuxt.options.tracingChannel === "object" && nuxt.options.tracingChannel.nuxt)) }; const lines = [ ...options.prelude ? [options.prelude] : [], `export { default as unheadOptions } from ${JSON.stringify(options.unheadOptions || "#build/unhead-options.mjs")}`, `export { iifeChunkFileName, renderSSRHeadOptions } from ${JSON.stringify(options.headConfig || "#build/unhead.config.mjs")}` ]; for (const name in values) { const key = name; lines.push(`export const ${key} = ${options.overrides?.[key] ?? values[key]}`); } return lines.join("\n"); } /** * The build-time replacements the renderer must be compiled with. A builder that does not * apply them ships both sides of every branch, and reaches the runtime with * `import.meta.prerender` undefined. * * @internal */ function getRendererDefines(phase, nuxt = useNuxt()) { return { "import.meta.dev": String(!!nuxt.options.dev), "import.meta.server": "true", "import.meta.client": "false", "import.meta.prerender": String(phase === "prerender") }; } /** * The module backing `nuxt/server` in the server bundle: the one the configured server * builder supplies, or the web-standard implementations Nuxt ships. * * The default is resolved to a file rather than left as `nuxt/server`, which the bundle * resolves to the module being generated here. */ function getServerSurfaceModule(nuxt) { const delegate = useServerBuild(nuxt).runtime.server; if (delegate) return delegate; return resolveNuxtModule("nuxt/server", nuxt); } function resolveNuxtModule(specifier, nuxt) { return resolveModulePath(specifier, { from: [...(nuxt.options.modulesDir || []).filter(Boolean).map((dir) => directoryToURL(dir)), import.meta.url] }); } /** * Version of the server runtime contract, bumped whenever a server builder has to do * something different with what {@link getServerRuntime} hands it. A builder compares it * against the version it was written for, so a mismatch is a build-time error rather than * a module that silently resolves to a stub. */ const SERVER_RUNTIME_VERSION = 1; /** * Everything core provides for a server builder to stand up the SSR renderer with: the * modules the renderer imports, the defines it must be compiled with, and the specifier * its server entry creates the renderer from. * * Core owns the set of modules, so a builder that iterates them keeps working when the set * changes; {@link SERVER_RUNTIME_VERSION} is what tells it when it cannot. * * @internal */ function getServerRuntime(options = {}, nuxt = useNuxt()) { const { phase = "server", overrides, ...rendererConfig } = options; const modules = { [RENDERER_CONFIG_SPECIFIER]: { code: async () => getRendererConfig({ ...rendererConfig, overrides: typeof overrides === "function" ? await overrides() : overrides }, nuxt) } }; for (const specifier in BUILD_OUTPUT_SPECIFIERS) { const output = BUILD_OUTPUT_SPECIFIERS[specifier]; modules[specifier] = { output, code: () => nuxt.buildOutputs[output]() }; } modules[SERVER_SPECIFIER] = { code: () => `export * from ${JSON.stringify(getServerSurfaceModule(nuxt))}` }; modules[SERVER_APP_CONFIG_SPECIFIER] = { code: () => nuxt.vfs["#build/app.config.mjs"]?.replace(APP_CONFIG_CLIENT_RE, "") || "export default {}" }; modules[DEV_ERROR_SPECIFIER] = { code: () => nuxt.options.dev ? `export * from ${JSON.stringify(resolveNuxtModule(DEV_ERROR_SPECIFIER, nuxt))}` : "export {}" }; modules[SERVER_RUNTIME_CONFIG_SPECIFIER] = { code: () => `export { useRuntimeConfig } from ${JSON.stringify(useServerBuild(nuxt).runtime.runtimeConfig)}` }; return { version: 1, modules, defines: getRendererDefines(phase, nuxt), entry: RENDERER_SPECIFIER }; } //#endregion export { DEFAULT_JSX_FILE_EXTENSIONS, DEFAULT_JS_FILE_EXTENSIONS, SERVER_RUNTIME_VERSION, buildDiagnostics, bundlerDiagnostics, componentDiagnostics, configDiagnostics, createServerBuild, findPackageMissingSubpath, getServerRuntime, hasOwnSubpathImport, headDiagnostics, installModules, kServerApi, kUnusedVariants, loadJiti, pageDiagnostics, parseNodeModulePath, pluginDiagnostics, reportPendingTemplates, resolveModuleExportNames, setServerBuild, trackPendingTemplate, useServerBuild };