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 locating the adapter package, adapter-auto reads its package.json exports map to find the entry point for the subpath (usually '.'). If the exports field has no entry matching the requested subpath (or no import/default fallback), the package.json is malformed or incompatible and this error is thrown.
Source
Thrown at packages/adapter-auto/index.js:72
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);
}
/** @typedef {import('@sveltejs/kit').Adapter} Adapter */
/**
* @returns {Promise<Adapter | undefined>} The corresponding adapter for the current environment if found otherwise undefined
*/
async function get_adapter() {
const match = adapters.find((candidate) => candidate.test());
if (!match) return;
View on GitHub (pinned to 03f1687fe6)
Solutions
- Delete node_modules and reinstall: rm -rf node_modules && npm install (or pnpm install).
- Verify node_modules/<adapter>/package.json has a valid exports field with '.' mapping to import/default.
- Reinstall the specific adapter: npm i -D @sveltejs/adapter-node.
- Use the adapter directly in svelte.config.js instead of resolving it through adapter-auto.
Example fix
// verify exports in node_modules/@sveltejs/adapter-node/package.json
// "exports": { ".": { "import": "./index.js", "default": "./index.js" } }
// if invalid: rm -rf node_modules package-lock.json && npm install Defensive patterns
Strategy: validation
Validate before calling
import fs from 'node:fs';
const pkgPath = './node_modules/@sveltejs/adapter-node/package.json';
if (!fs.existsSync(pkgPath)) throw new Error('adapter not installed');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
if (!pkg.exports || !pkg.exports['.']) throw new Error(`${pkg.name} has an invalid exports map — reinstall it`); Type guard
const hasValidExports = (pkg) =>
!!pkg?.exports && Object.values(pkg.exports).some((v) =>
typeof v === 'string' || (v && typeof v === 'object' && ('import' in v || 'default' in v))
); Try / catch
try {
await build();
} catch (e) {
if (/Could not find valid .* export in .*\/package\.json/.test(e.message)) {
console.error('Corrupted/incompatible adapter package — run: rm -rf node_modules && npm install');
process.exit(1);
}
throw e;
} Prevention
- Do a clean reinstall after interrupted installs
- Pin adapter versions and commit the lockfile
- Don't hand-edit packages in node_modules
- Validate package.json exports when vendoring adapters
When it happens
Trigger: resolve_peer found node_modules/<name>/package.json but pkg.exports does not contain a string or an object with 'import'/'default' keys for the resolved subpackage path (typically '.').
Common situations: A partially installed or corrupted node_modules directory (interrupted install); a manually vendored adapter package with a nonstandard or missing exports field; a stale lockfile producing an incompatible package version.
Related errors
- Could not resolve peer dependency "${name}" relative to your
- Could not install ${match.module}. Please install it yoursel
- ${message}. Since you're using @sveltejs/adapter-auto, Svelt
- If you plan to continue deploying to ${match.name}, conside
- Could not detect a supported production environment. See htt
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/753cf1718d8766e1.
Report an issue: GitHub.