sveltejs/kit · error · Error
Could not resolve peer dependency
Error message
Could not resolve peer dependency "${name}" relative to your project — please install it and try again. What it means
adapter-auto resolves its peer adapter packages (e.g. @sveltejs/adapter-node) by walking up from process.cwd() looking for node_modules/<name>/package.json. When the directory walk reaches the filesystem root without finding the package, it throws this error meaning the detected environment's adapter is not installed in the project.
Solutions
- Install the adapter the auto-detector chose: npm i -D @sveltejs/adapter-node (or whichever adapter matches your platform).
- Check package.json devDependencies include the adapter and run a full install (not --production).
- In monorepos, add the adapter to the app package's devDependencies or configure hoisting so it lands in a resolvable node_modules.
- Bypass auto-detection by importing the specific adapter directly in svelte.config.js.
Example fix
// before
// svelte.config.js uses adapter-auto, deploying to Vercel without the adapter installed
// after
import adapter from '@sveltejs/adapter-vercel';
export default { kit: { adapter: adapter() } }; Defensive patterns
Strategy: validation
Validate before calling
import fs from 'node:fs';
import path from 'node:path';
const adapters = ['@sveltejs/adapter-node','@sveltejs/adapter-vercel','@sveltejs/adapter-netlify','@sveltejs/adapter-cloudflare','@sveltejs/adapter-bun'];
const resolvable = (name) => {
let dir = process.cwd();
while (true) {
if (fs.existsSync(path.join(dir, 'node_modules', name, 'package.json'))) return true;
const parent = path.dirname(dir);
if (parent === dir) return false;
dir = parent;
}
};
// before build: ensure the adapter you expect is resolvable
if (!adapters.some(resolvable)) throw new Error('No platform adapter installed — add one to devDependencies'); Type guard
const isAdapterInstalled = (name) => {
let dir = process.cwd();
while (true) {
if (fs.existsSync(path.join(dir, 'node_modules', name, 'package.json'))) return true;
const parent = path.dirname(dir);
if (parent === dir) return false;
dir = parent;
}
}; Try / catch
try {
await build();
} catch (e) {
const m = /Could not resolve peer dependency "([^"]+)"/.exec(e.message);
if (m) {
console.error(`Missing adapter ${m[1]}. Run: npm i -D ${m[1]}`);
process.exit(1);
}
throw e;
} Prevention
- Commit the platform adapter to package.json devDependencies instead of relying on adapter-auto alone
- Never install with --production/--prod for build pipelines
- In monorepos, declare the adapter in the app package that runs the build
- Verify node_modules contents after fresh CI checkouts
When it happens
Trigger: get_adapter detected a deployment environment (via environment variables), mapped it to an adapter module name, and resolve_peer could not find that package's package.json in any node_modules directory between the project root and the filesystem root.
Common situations: Fresh CI environments where devDependencies were not installed (e.g. npm install --production or pnpm install --prod); monorepos where the adapter is in a different workspace package that isn't hoisted; adapters deleted from package.json while relying on auto-detection.
Related errors
- Could not find valid
- Could not detect a supported production environment. See…
- Could not install . Please install it yourself by adding it…
- Could not resolve peer dependency
- If you plan to continue deploying to
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/af1569a1417508fb.
Report an issue: GitHub.
Appendix: source
Thrown at packages/adapter-auto/index.js:57
return manager;
} catch {
return 'npm';
}
}
/**
* Resolves a peer dependency relative to the current CWD. Duplicated with `packages/kit`
* @param {string} dependency
*/
function resolve_peer(dependency) {
let [name, ...parts] = dependency.split('/');
if (name[0] === '@') name += `/${parts.shift()}`;
let dir = process.cwd();
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'];View on GitHub (pinned to 03f1687fe6)