{"record":{"id":"029d085a193432b7","repo":"sveltejs/kit","slug":"could-not-resolve-peer-dependency-name-relati-029d08","errorCode":null,"errorMessage":"Could not resolve peer dependency \"${name}\" relative to your project — please install it and try again.","messagePattern":"Could not resolve peer dependency \"(.+?)\" relative to your project — please install it and try again\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/utils/import.js","lineNumber":23,"sourceCode":"/**\n * Resolves a peer dependency relative to the current working directory.\n *\n * Mainly used to resolve the correct Vite package when an app's SvelteKit is a\n * linked local repository.\n *\n * Duplicated with `packages/adapter-auto`\n * @param {string} dependency\n * @param {string} root\n */\nfunction resolve_peer(dependency, root) {\n\tlet [name, ...parts] = dependency.split('/');\n\tif (name[0] === '@') name += `/${parts.shift()}`;\n\n\tlet dir = root;\n\n\twhile (!fs.existsSync(`${dir}/node_modules/${name}/package.json`)) {\n\t\tif (dir === (dir = path.dirname(dir))) {\n\t\t\tthrow new Error(\n\t\t\t\t`Could not resolve peer dependency \"${name}\" relative to your project — please install it and try again.`\n\t\t\t);\n\t\t}\n\t}\n\n\tconst pkg_dir = `${dir}/node_modules/${name}`;\n\tconst pkg = JSON.parse(fs.readFileSync(`${pkg_dir}/package.json`, 'utf-8'));\n\n\tconst subpackage = ['.', ...parts].join('/');\n\n\tlet exported = pkg.exports[subpackage];\n\n\twhile (typeof exported !== 'string') {\n\t\tif (!exported) {\n\t\t\tthrow new Error(`Could not find valid \"${subpackage}\" export in ${name}/package.json`);\n\t\t}\n\n\t\texported = exported['import'] ?? exported['default'];","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/utils/import.js#L5-L41","documentation":"import_peer/resolve_peer resolve an optional peer dependency (e.g. @sveltejs/vite-plugin-svelte, typescript) starting from the project root and walking up directories, looking for node_modules/<name>/package.json. If the package is installed nowhere up the tree, Kit throws this error telling you to install it.","triggerScenarios":"Running kit commands (dev/build, sync, or tooling that calls import_peer) with a required peer dependency not present in any node_modules between the project and filesystem root — typically the package simply isn't installed, or is only present in a sibling workspace.","commonSituations":"Fresh clone without `pnpm install`; peer dep listed in package.json but forgotten; npm/peer-dep auto-install disabled (npm <7 or --legacy-peer-deps); monorepo where the dep is in another package's node_modules only.","solutions":["Install the missing package: `pnpm add -D <name>` (or npm/yarn equivalent)","Run the package manager install for the whole workspace (`pnpm install`) so hoisting places it in the root node_modules","Verify it exists: check for node_modules/<name>/package.json in the project root","If using --legacy-peer-deps or npm 6, install peers explicitly"],"exampleFix":"// before (package.json devDependencies)\n{}\n// after\n{ \"devDependencies\": { \"@sveltejs/vite-plugin-svelte\": \"^5.0.0\" } }","handlingStrategy":"try-catch","validationCode":"const fs = require('fs');\nconst peerInstalled = (name, root = process.cwd()) =>\n  fs.existsSync(`${root}/node_modules/${name}/package.json`);","typeGuard":"const isPeerAvailable = (name) => {\n  try { return !!require.resolve(`${name}/package.json`); } catch { return false; }\n};","tryCatchPattern":"try {\n  const mod = importPeer('@sveltejs/vite-plugin-svelte');\n} catch (e) {\n  if (e.message.includes('Could not resolve peer dependency')) {\n    console.error(`Run: pnpm add -D ${name}`);\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Commit a lockfile and always run `pnpm install` after checkout","List required peer dependencies explicitly in devDependencies","Avoid --legacy-peer-deps installs that skip peers","In monorepos, install at the workspace root so hoisting works"],"tags":["dependencies","install","peer-dependency"],"backgroundTag":"missing-peer-dependency","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}