{"record":{"id":"5218bf9614cec969","repo":"vitejs/vite","slug":"vite-rolldown-failed-to-resolve-import-expor","errorCode":null,"errorMessage":"[vite]: Rolldown failed to resolve import \"${exporter}\" from \"${id}\".\nThis is most likely unintended because it can break your application at runtime.\nIf you do want to externalize this module explicitly add it to\n`build.rolldownOptions.external`","messagePattern":"\\[vite\\]: Rolldown failed to resolve import \"(.+?)\" from \"(.+?)\"\\.\nThis is most likely unintended because it can break your application at runtime\\.\nIf you do want to externalize this module explicitly add it to\n`build\\.rolldownOptions\\.external`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/build.ts","lineNumber":1133,"sourceCode":"  }\n}\n\nexport function onRollupLog(\n  level: LogLevel,\n  log: RollupLog,\n  environment: Environment,\n): void {\n  const debugLogger = createDebugger('vite:build')\n  const viteLog: LogOrStringHandler = (logLeveling, rawLogging) => {\n    const logging =\n      typeof rawLogging === 'object' ? rawLogging : { message: rawLogging }\n\n    if (logging.code === 'UNRESOLVED_IMPORT') {\n      const id = logging.id\n      const exporter = logging.exporter\n      // throw unless it's commonjs external...\n      if (!id || !id.endsWith('?commonjs-external')) {\n        throw new Error(\n          `[vite]: Rolldown failed to resolve import \"${exporter}\" from \"${id}\".\\n` +\n            `This is most likely unintended because it can break your application at runtime.\\n` +\n            `If you do want to externalize this module explicitly add it to\\n` +\n            `\\`build.rolldownOptions.external\\``,\n        )\n      }\n    }\n\n    if (logLeveling === 'warn') {\n      if (\n        logging.plugin === 'rollup-plugin-dynamic-import-variables' &&\n        dynamicImportWarningIgnoreList.some((msg) =>\n          logging.message.includes(msg),\n        )\n      ) {\n        return\n      }\n","sourceCodeStart":1115,"sourceCodeEnd":1151,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/node/build.ts#L1115-L1151","documentation":"Rolldown emits an UNRESOLVED_IMPORT log for any specifier it cannot resolve. Vite's onRollupLog handler re-throws that log as an error unless the importer is a CommonJS external shim (?commonjs-external). The message tells you which exporter could not be resolved from which file and points at build.rolldownOptions.external as the explicit-externalize escape hatch.","triggerScenarios":"Source code imports a bare specifier that is not installed, not a Node builtin, and not listed in external. Typical with peer deps, optional deps, or typos. Also when an SSR build references a package that lives only in dependenciesUsed but is not externalized.","commonSituations":"Forgetting to install a package; importing a peer dependency without declaring it external; importing Node built-ins (fs, path) in client code; referencing a workspace package whose name does not match.","solutions":["Install the missing package: npm install <exporter>.","If it is a peer/runtime dep, add it to build.rollupOptions.external (or ssr.external for SSR).","Fix typos in the import specifier; check it matches the package name exactly.","For Node built-ins in SSR code, ensure the environment is configured as node, not browser."],"exampleFix":"// before\n// app imports 'lodash.debounce' but it is not installed\n// after (option A)\n//   npm install lodash.debounce\n// after (option B - externalize)\nbuild: { rollupOptions: { external: ['lodash.debounce'] } }","handlingStrategy":"try-catch","validationCode":"const fs = require('fs');\nfunction canResolve(specifier, importer) {\n  try { require.resolve(specifier, { paths: [require('path').dirname(importer)] }); return true; } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await vite.build();\n} catch (e) {\n  if (e && /Rolldown failed to resolve import/.test(String(e.message))) {\n    const m = e.message.match(/import \"([^\"]+)\"/);\n    const missing = m?.[1];\n    external.push(missing);\n    await vite.build();\n  } else throw e;\n}","preventionTips":["List peer/runtime dependencies in build.rolldownOptions.external.","Run npm ls before building to catch missing packages.","CI: install with --frozen-lockfile so missing deps fail early."],"tags":["build","resolve","external","bundling"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}