{"record":{"id":"4ca612f4c43c196b","repo":"sveltejs/kit","slug":"could-not-find-valid-subpackage-export-in-n-4ca612","errorCode":null,"errorMessage":"Could not find valid \"${subpackage}\" export in ${name}/package.json","messagePattern":"Could not find valid \"(.+?)\" export in (.+?)/package\\.json","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/utils/import.js","lineNumber":38,"sourceCode":"\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'];\n\t}\n\n\treturn path.resolve(pkg_dir, exported);\n}\n\n/**\n * Resolve a dependency relative to the current working directory,\n * rather than relative to this package (but falls back to trying that, if necessary)\n * @param {string} dependency\n * @param {string} root\n */\nexport async function import_peer(dependency, root) {\n\ttry {\n\t\treturn await import(/* @vite-ignore */ pathToFileURL(resolve_peer(dependency, root)).href);\n\t} catch {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/utils/import.js#L20-L56","documentation":"After locating a peer package's directory, resolve_peer walks its package.json `exports` map to find the requested subpackage (e.g. '@sveltejs/kit/src'). If the exports entry is absent or not a resolvable string/conditional object, Kit throws this error.","triggerScenarios":"Requesting a subpath export that the package doesn't declare in `exports`, a typo'd subpath (e.g. wrong casing or missing segment), or an outdated/incompatible version of the peer package whose exports map lacks the needed entry.","commonSituations":"Version mismatch: newer Kit expects an export the installed peer doesn't have; typos in subpath imports; packages with restrictive exports maps; manually editing node_modules.","solutions":["Update the peer package to a version that declares the subpath export (pnpm update <name>)","Check package.json `exports` of the installed package for the exact subpath spelling","Fix typos in the requested subpath (case-sensitive, leading '.' forms)","Reinstall clean (rm -rf node_modules && pnpm install) if node_modules is corrupted or hand-edited"],"exampleFix":"// before\nimportPeer('@sveltejs/vite-plugin-svelte/src/wrong-path');\n// after\nimportPeer('@sveltejs/vite-plugin-svelte/src/index.js'); // verify against its package.json exports","handlingStrategy":"validation","validationCode":"const pkg = require(`${pkgDir}/package.json`);\nconst exportExists = (name, sub) => {\n  const e = pkg.exports?.[sub];\n  return typeof e === 'string' || (e && ('import' in e || 'default' in e));\n};","typeGuard":"const hasValidExport = (exports, sub) =>\n  !!exports && [sub].some((s) => {\n    const e = exports[s];\n    return typeof e === 'string' || (e && typeof e === 'object' && ('import' in e || 'default' in e));\n  });","tryCatchPattern":"try {\n  const resolved = importPeer('@sveltejs/kit/src');\n} catch (e) {\n  if (e.message.includes('Could not find valid')) {\n    console.error('Subpath not in package exports — check the installed version\\'s exports map');\n  } else throw e;\n}","preventionTips":["Match Kit and peer package versions (per Kit's peerDependencies ranges)","Verify subpath spelling against the package's package.json exports","Avoid hand-editing node_modules; reinstall clean instead","Add a version check step in CI before builds that use import_peer"],"tags":["dependencies","exports","package-json"],"backgroundTag":"missing-subpath-export","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}