vitejs/vite · error · Error

[vite]: Rolldown failed to resolve import "${exporter}" from

Error message

[vite]: Rolldown failed to resolve import "${exporter}" from "${id}".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rolldownOptions.external`

What it means

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.

Source

Thrown at packages/vite/src/node/build.ts:1129

  }
}

export function onRollupLog(
  level: LogLevel,
  log: RollupLog,
  environment: Environment,
): void {
  const debugLogger = createDebugger('vite:build')
  const viteLog: LogOrStringHandler = (logLeveling, rawLogging) => {
    const logging =
      typeof rawLogging === 'object' ? rawLogging : { message: rawLogging }

    if (logging.code === 'UNRESOLVED_IMPORT') {
      const id = logging.id
      const exporter = logging.exporter
      // throw unless it's commonjs external...
      if (!id || !id.endsWith('?commonjs-external')) {
        throw new Error(
          `[vite]: Rolldown failed to resolve import "${exporter}" from "${id}".\n` +
            `This is most likely unintended because it can break your application at runtime.\n` +
            `If you do want to externalize this module explicitly add it to\n` +
            `\`build.rolldownOptions.external\``,
        )
      }
    }

    if (logLeveling === 'warn') {
      if (
        logging.plugin === 'rollup-plugin-dynamic-import-variables' &&
        dynamicImportWarningIgnoreList.some((msg) =>
          logging.message.includes(msg),
        )
      ) {
        return
      }

View on GitHub (pinned to 89620f09af)

Solutions

  1. Install the missing dependency: npm install <package>.
  2. If the import should not be bundled, add it to build.rolldownOptions.external.
  3. Fix the import path/typo or ensure the file extension resolution is configured.
  4. Verify the package is exported by its package.json 'exports' for the conditions Vite uses.

Example fix

// before
import foo from 'some-pkg' // not installed, not external
// after (option A)
// $ npm install some-pkg
// after (option B - externalize)
build: { rolldownOptions: { external: ['some-pkg'] } }
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-build, verify resolvability of bare imports
import { createImporter } from 'vite'
// Or simpler: ensure deps are installed
const deps = ['some-pkg'] // specifiers you import
const missing = deps.filter((d) => !require.resolve.paths(d))

Try / catch

try {
  await build(config)
} catch (e) {
  if (e instanceof Error && e.message.includes('Rolldown failed to resolve import')) {
    const m = e.message.match(/resolve import "([^"]+)"/)
    console.error('Unresolved import:', m?.[1], '- install it or add to build.rolldownOptions.external')
  }
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of vitejs/vite@89620f09af (2026-08-03). Data as JSON: /data/errors/5218bf9614cec969.json. Report an issue: GitHub.