{"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":1129,"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":1111,"sourceCodeEnd":1147,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/build.ts#L1111-L1147","documentation":"In onRollupLog (build.ts:1124-1135), when Rolldown emits an UNRESOLVED_IMPORT log (code 'UNRESOLVED_IMPORT') for a non-commonjs-external id, Vite re-throws it as an error. An unresolved import means a module referenced in source could not be found on the resolver, which would break the app at runtime, so Vite treats it as fatal unless explicitly externalized.","triggerScenarios":"Importing a bare specifier (e.g. 'some-pkg') in source during build where the package isn't installed, isn't resolvable, and isn't listed in build.rolldownOptions.external; also when a path is misspelled or an extension is omitted and not resolvable.","commonSituations":"Missing dependency in package.json (forgot to install), conditional import of a Node-only package in a client build, monorepo package not symlinked, typo'd import path.","solutions":["Install the missing dependency: npm install <package>.","If the import should not be bundled, add it to build.rolldownOptions.external.","Fix the import path/typo or ensure the file extension resolution is configured.","Verify the package is exported by its package.json 'exports' for the conditions Vite uses."],"exampleFix":"// before\nimport foo from 'some-pkg' // not installed, not external\n// after (option A)\n// $ npm install some-pkg\n// after (option B - externalize)\nbuild: { rolldownOptions: { external: ['some-pkg'] } }","handlingStrategy":"try-catch","validationCode":"// Pre-build, verify resolvability of bare imports\nimport { createImporter } from 'vite'\n// Or simpler: ensure deps are installed\nconst deps = ['some-pkg'] // specifiers you import\nconst missing = deps.filter((d) => !require.resolve.paths(d))","typeGuard":null,"tryCatchPattern":"try {\n  await build(config)\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Rolldown failed to resolve import')) {\n    const m = e.message.match(/resolve import \"([^\"]+)\"/)\n    console.error('Unresolved import:', m?.[1], '- install it or add to build.rolldownOptions.external')\n  }\n  throw e\n}","preventionTips":["Run npm install / check package.json before building.","Intentionally externalize server-only or peer packages in rolldownOptions.external.","Use a dependency check tool (e.g. depcheck) to catch missing imports."],"tags":["build","resolve","dependency","external"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}