{"record":{"id":"d0db643b24b017ed","repo":"sveltejs/kit","slug":"could-not-find-valid-subpackage-export-in-n-d0db64","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/package/src/config.js","lineNumber":78,"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","sourceCodeStart":60,"sourceCodeEnd":86,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/package/src/config.js#L60-L86","documentation":"After resolving a peer package's directory, `resolve_peer` looks up the requested subpath in the package's `exports` map of package.json, walking `import`/`default` conditions. If the subpath key is absent or resolves to null/undefined, it throws because the package does not expose that entry point.","triggerScenarios":"`import_peer('<name>/<deep/subpath>')` (via resolve_peer) where `<name>/package.json` has an `exports` field that does not include the `./<subpath>` key, or the entry resolves to conditions without a usable `import`/`default` value.","commonSituations":"Importing an ESM-only or exports-restricted package via a deep path it no longer publishes; version drift where the peer package renamed/removed a subpath export; packages that restrict exports to `.` only.","solutions":["Check the peer package's `exports` map and import a path that exists (usually the bare package name).","Upgrade or pin the peer dependency to a version that exports the requested subpath.","If you own the peer package, add the missing `./<subpath>` export to its package.json."],"exampleFix":"// before\nconst ts = await import('typescript/lib/typescript.js');\n\n// after\nconst ts = await import('typescript');","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nconst pkg = JSON.parse(fs.readFileSync('node_modules/some-pkg/package.json', 'utf8'));\nif (pkg.exports && !('' in pkg.exports)) throw new Error('some-pkg has no root export');","typeGuard":"function hasExport(pkg, subpath) {\n  return !pkg.exports || subpath in pkg.exports;\n}","tryCatchPattern":"try {\n  mod = await import('some-pkg/deep/path');\n} catch (e) {\n  if (String(e.message).includes('Could not find valid')) mod = await import('some-pkg');\n  else throw e;\n}","preventionTips":["Import packages by their root name unless the exports map advertises the subpath","Inspect the peer's package.json exports before deep-importing","Pin peer versions so their export surface is stable"],"tags":["package-json","exports","module-resolution","peer-dependency"],"backgroundTag":"missing-package-export","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}