{"record":{"id":"cade591a28d203f1","repo":"sveltejs/kit","slug":"could-not-resolve-peer-dependency-name-relati-cade59","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/package/src/config.js","lineNumber":63,"sourceCode":"\t\t// eslint-disable-next-line kit-node-custom/require-path-to-file-url -- bare package specifier, not a path\n\t\treturn await import(/* @vite-ignore */ dependency);\n\t}\n}\n\n/**\n * Resolves a peer dependency relative to the current working directory. 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":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/package/src/config.js#L45-L81","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n# package.json lacks typescript\n\n// after\nnpm i -D typescript","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nimport path from 'node:path';\nconst peer = 'typescript';\nlet dir = process.cwd();\nwhile (!fs.existsSync(path.join(dir, 'node_modules', peer, 'package.json')) && dir !== path.dirname(dir)) dir = path.dirname(dir);\nif (!fs.existsSync(path.join(dir, 'node_modules', peer, 'package.json'))) throw new Error(`${peer} not installed`);","typeGuard":null,"tryCatchPattern":"try {\n  await run(['svelte-package']);\n} catch (e) {\n  if (String(e.message).includes('Could not resolve peer dependency')) {\n    const name = e.message.match(/\"(.+?)\"/)[1];\n    throw new Error(`Install ${name} first: npm i -D ${name}`);\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["dependencies","node-modules","peer-dependency","installation"],"backgroundTag":"peer-dependency-not-found","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}