sveltejs/kit · error · Error

Could not load ${resolved_id}

Error message

Could not load ${resolved_id}

What it means

enhanced-img delegates image loading/transformation to vite-imagetools' load hook. When calling that hook for a resolved id returns nothing (falsy module info), enhanced-img cannot produce the image module and throws.

Source

Thrown at packages/enhanced-img/src/vite-plugin.js:240

	};
	return plugin;
}

/**
 * @param {string} resolved_id
 * @param {import('vite').Rollup.PluginContext} plugin_context
 * @param {import('vite').Plugin} imagetools_plugin
 * @returns {Promise<import('vite-imagetools').Picture>}
 */
async function process_id(resolved_id, plugin_context, imagetools_plugin) {
	if (!imagetools_plugin.load) {
		throw new Error('Invalid instance of vite-imagetools. Could not find load method.');
	}
	const hook = imagetools_plugin.load;
	const handler = typeof hook === 'object' ? hook.handler : hook;
	const module_info = await handler.call(plugin_context, resolved_id);
	if (!module_info) {
		throw new Error(`Could not load ${resolved_id}`);
	}
	const code = typeof module_info === 'string' ? module_info : module_info.code;
	return parse_object(code.replace('export default', '').replace(/;$/, '').trim());
}

/**
 * @param {string} str
 */
export function parse_object(str) {
	const updated = str
		.replaceAll(/{(\n\s*)?/gm, '{"')
		.replaceAll(':', '":')
		.replaceAll(/,(\n\s*)?([^ ])/g, ',"$2');
	try {
		return JSON.parse(updated);
	} catch {
		throw new Error(`Failed parsing string to object: ${str}`);
	}

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Verify a compatible vite-imagetools version is installed and included in the Vite plugins
  2. Ensure the image URL uses optimizable extensions and expected query parameters (e.g. ?w=800&format=webp)
  3. Reinstall node_modules to clear mismatched plugin hoisting
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await build();
} catch (e) {
  if (String(e.message).startsWith('Could not load')) {
    console.error('vite-imagetools failed to handle the image; check plugin config/version');
  }
  throw e;
}

Prevention

When it happens

Trigger: `process_id` invokes the imagetools plugin's load handler with the resolved id and receives undefined/null — the imagetools plugin did not handle the id (e.g. wrong extension or missing query params for optimization).

Common situations: An incompatible or misconfigured vite-imagetools instance, an image id that imagetools does not consider optimizable, or the imagetools plugin being replaced/absent so its load hook returns nothing.

Related errors


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