sveltejs/kit · error · Error
Could not resolve peer dependency "${name}" relative to your
Error message
Could not resolve peer dependency "${name}" relative to your project — please install it and try again. What it means
`resolve_peer` walks up from the project root looking for `node_modules/<name>/package.json` to import a peer dependency. If the directory tree is exhausted without finding it, it throws this error telling you the peer package must be installed relative to your project.
Source
Thrown at packages/package/src/config.js:63
// eslint-disable-next-line kit-node-custom/require-path-to-file-url -- bare package specifier, not a path
return await import(/* @vite-ignore */ dependency);
}
}
/**
* Resolves a peer dependency relative to the current working directory. Duplicated with `packages/adapter-auto`
* @param {string} dependency
* @param {string} root
*/
function resolve_peer(dependency, root) {
let [name, ...parts] = dependency.split('/');
if (name[0] === '@') name += `/${parts.shift()}`;
let dir = root;
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)
Solutions
- Install the missing peer in the project: `npm i -D <name>`.
- In pnpm workspaces, add the peer to the package's devDependencies (or use `pnpm add -D <name>` in the project) so it is linked into node_modules.
- Run the CLI from the project root so `root` resolves to the correct directory.
- Verify `node_modules/<name>/package.json` exists after install.
Example fix
// before # package.json lacks typescript // after npm i -D typescript
Defensive patterns
Strategy: validation
Validate before calling
import fs from 'node:fs';
import path from 'node:path';
const peer = 'typescript';
let dir = process.cwd();
while (!fs.existsSync(path.join(dir, 'node_modules', peer, 'package.json')) && dir !== path.dirname(dir)) dir = path.dirname(dir);
if (!fs.existsSync(path.join(dir, 'node_modules', peer, 'package.json'))) throw new Error(`${peer} not installed`); Try / catch
try {
await run(['svelte-package']);
} catch (e) {
if (String(e.message).includes('Could not resolve peer dependency')) {
const name = e.message.match(/"(.+?)"/)[1];
throw new Error(`Install ${name} first: npm i -D ${name}`);
}
throw e;
} Prevention
- Declare all tooling peers (typescript, preprocessors) in devDependencies
- Always run npm/pnpm install after cloning before build scripts
- In pnpm, verify peers appear in the project's node_modules, not only the workspace root
When it happens
Trigger: Running `svelte-package` in a project that uses a TypeScript config or depends on a tool (e.g. typescript, a preprocessor) that @sveltejs/package resolves via `import_peer`, when that peer package is not installed in the project or any ancestor node_modules.
Common situations: Fresh clone without `npm install`; peer dependency present only in a global install instead of locally; monorepo where the package is hoisted outside the searched root; pnpm strict node_modules where the peer was never declared.
Related errors
- Could not resolve peer dependency "${name}" relative to your
- You need to install TypeScript if you want to transpile Type
- Could not resolve peer dependency "${name}" relative to your
- Could not find valid "${subpackage}" export in ${name}/packa
- Could not find valid "${subpackage}" export in ${name}/packa
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/cade591a28d203f1.
Report an issue: GitHub.