sveltejs/kit · error · Error

Could not find valid "${subpackage}" export in ${name}/packa

Error message

Could not find valid "${subpackage}" export in ${name}/package.json

What it means

After resolving a peer package's directory, `resolve_peer` looks up the requested subpath in the package's `exports` map of package.json, walking `import`/`default` conditions. If the subpath key is absent or resolves to null/undefined, it throws because the package does not expose that entry point.

Source

Thrown at packages/package/src/config.js:78

	while (!fs.existsSync(`${dir}/node_modules/${name}/package.json`)) {
		if (dir === (dir = path.dirname(dir))) {
			throw new Error(
				`Could not resolve peer dependency "${name}" relative to your project — please install it and try again.`
			);
		}
	}

	const pkg_dir = `${dir}/node_modules/${name}`;
	const pkg = JSON.parse(fs.readFileSync(`${pkg_dir}/package.json`, 'utf-8'));

	const subpackage = ['.', ...parts].join('/');

	let exported = pkg.exports[subpackage];

	while (typeof exported !== 'string') {
		if (!exported) {
			throw new Error(`Could not find valid "${subpackage}" export in ${name}/package.json`);
		}

		exported = exported['import'] ?? exported['default'];
	}

	return path.resolve(pkg_dir, exported);
}

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Check the peer package's `exports` map and import a path that exists (usually the bare package name).
  2. Upgrade or pin the peer dependency to a version that exports the requested subpath.
  3. If you own the peer package, add the missing `./<subpath>` export to its package.json.

Example fix

// before
const ts = await import('typescript/lib/typescript.js');

// after
const ts = await import('typescript');
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'node:fs';
const pkg = JSON.parse(fs.readFileSync('node_modules/some-pkg/package.json', 'utf8'));
if (pkg.exports && !('' in pkg.exports)) throw new Error('some-pkg has no root export');

Type guard

function hasExport(pkg, subpath) {
  return !pkg.exports || subpath in pkg.exports;
}

Try / catch

try {
  mod = await import('some-pkg/deep/path');
} catch (e) {
  if (String(e.message).includes('Could not find valid')) mod = await import('some-pkg');
  else throw e;
}

Prevention

When it happens

Trigger: `import_peer('<name>/<deep/subpath>')` (via resolve_peer) where `<name>/package.json` has an `exports` field that does not include the `./<subpath>` key, or the entry resolves to conditions without a usable `import`/`default` value.

Common situations: Importing an ESM-only or exports-restricted package via a deep path it no longer publishes; version drift where the peer package renamed/removed a subpath export; packages that restrict exports to `.` only.

Related errors


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