sveltejs/kit · warning

Warning: The following modules failed to locate dependencies

Error message

Warning: The following modules failed to locate dependencies that may (or may not) be required for your app to work:

What it means

During create_function_bundle, the Vercel adapter (via esbuild/nft-style tracing) tries to resolve every import of every bundled module. Imports that cannot be resolved are recorded in `resolution_failures` and reported with this warning: the code may require those packages at runtime, but they were not traced into the function bundle. It says 'may (or may not)' because some failures are for optional or dynamically-loaded dependencies that never execute.

Source

Thrown at packages/adapter-vercel/index.js:580

		if (error.message.startsWith('Failed to parse')) return;

		if (error.message.startsWith('Failed to resolve dependency')) {
			const match = /Cannot find module '(.+?)' loaded from (.+)/;
			const [, module, importer] = match.exec(error.message) ?? [, error.message, '(unknown)'];

			if (!resolution_failures.has(importer)) {
				resolution_failures.set(importer, []);
			}

			/** @type {string[]} */ (resolution_failures.get(importer)).push(module);
		} else {
			throw error;
		}
	});

	if (resolution_failures.size > 0) {
		const cwd = process.cwd();
		builder.log.warn(
			'Warning: The following modules failed to locate dependencies that may (or may not) be required for your app to work:'
		);

		for (const [importer, modules] of resolution_failures) {
			console.error(`  ${path.relative(cwd, importer)}`);
			for (const module of modules) {
				console.error(`    - \u001B[1m\u001B[36m${module}\u001B[39m\u001B[22m`);
			}
		}
	}

	const files = Array.from(traced.fileList);

	// find common ancestor directory
	/** @type {string[]} */
	let common_parts = files[0]?.split(path.sep) ?? [];

	for (let i = 1; i < files.length; i += 1) {

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Add the unresolved packages to your package.json dependencies and reinstall so the tracer can resolve them.
  2. If the module is optional and genuinely unused, ignore the warning.
  3. Check the listed importer paths to identify which package's optional dependency is failing and install that parent's peer deps.
  4. Use the `external` adapter option to mark packages that should stay external to the bundle and be installed at runtime instead.

Example fix

// before
npm i   # sharp present but @img/sharp-lib optional variants absent
# after
npm i -D @img/sharp-linux-x64  # or install the missing dependency named in the warning
Defensive patterns

Strategy: validation

Validate before calling

// Pre-build dependency sanity check
import { existsSync } from 'node:fs';
for (const dep of optionalDeps) {
  if (!existsSync(`node_modules/${dep}`)) console.warn(`Unresolved dep likely in bundle: ${dep}`);
}

Prevention

When it happens

Trigger: Running generate_serverless_function when esbuild's onResolve handler fails for one or more importers' modules (e.g. optional peer dependencies, native/dynamic requires, packages not in node_modules at build time).

Common situations: Dependencies imported dynamically or conditionally that are missing from package.json; optional peer deps of frameworks; monorepo workspace links that don't resolve under the bundler; platform-specific optional dependencies (e.g. sharp variants).

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/3f8ec19f85bf50eb. Report an issue: GitHub.