{"record":{"id":"753cf1718d8766e1","repo":"sveltejs/kit","slug":"could-not-find-valid-subpackage-export-in-n","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/adapter-auto/index.js","lineNumber":72,"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/** @typedef {import('@sveltejs/kit').Adapter} Adapter */\n\n/**\n * @returns {Promise<Adapter | undefined>} The corresponding adapter for the current environment if found otherwise undefined\n */\nasync function get_adapter() {\n\tconst match = adapters.find((candidate) => candidate.test());\n\n\tif (!match) return;\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-auto/index.js#L54-L90","documentation":"After locating the adapter package, adapter-auto reads its package.json exports map to find the entry point for the subpath (usually '.'). If the exports field has no entry matching the requested subpath (or no import/default fallback), the package.json is malformed or incompatible and this error is thrown.","triggerScenarios":"resolve_peer found node_modules/<name>/package.json but pkg.exports does not contain a string or an object with 'import'/'default' keys for the resolved subpackage path (typically '.').","commonSituations":"A partially installed or corrupted node_modules directory (interrupted install); a manually vendored adapter package with a nonstandard or missing exports field; a stale lockfile producing an incompatible package version.","solutions":["Delete node_modules and reinstall: rm -rf node_modules && npm install (or pnpm install).","Verify node_modules/<adapter>/package.json has a valid exports field with '.' mapping to import/default.","Reinstall the specific adapter: npm i -D @sveltejs/adapter-node.","Use the adapter directly in svelte.config.js instead of resolving it through adapter-auto."],"exampleFix":"// verify exports in node_modules/@sveltejs/adapter-node/package.json\n// \"exports\": { \".\": { \"import\": \"./index.js\", \"default\": \"./index.js\" } }\n// if invalid: rm -rf node_modules package-lock.json && npm install","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nconst pkgPath = './node_modules/@sveltejs/adapter-node/package.json';\nif (!fs.existsSync(pkgPath)) throw new Error('adapter not installed');\nconst pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));\nif (!pkg.exports || !pkg.exports['.']) throw new Error(`${pkg.name} has an invalid exports map — reinstall it`);","typeGuard":"const hasValidExports = (pkg) =>\n  !!pkg?.exports && Object.values(pkg.exports).some((v) =>\n    typeof v === 'string' || (v && typeof v === 'object' && ('import' in v || 'default' in v))\n  );","tryCatchPattern":"try {\n  await build();\n} catch (e) {\n  if (/Could not find valid .* export in .*\\/package\\.json/.test(e.message)) {\n    console.error('Corrupted/incompatible adapter package — run: rm -rf node_modules && npm install');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Do a clean reinstall after interrupted installs","Pin adapter versions and commit the lockfile","Don't hand-edit packages in node_modules","Validate package.json exports when vendoring adapters"],"tags":["package-exports","adapter-auto","dependency-resolution"],"backgroundTag":"invalid-package-exports","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}