{"record":{"id":"fd91494743190f4e","repo":"slidevjs/slidev","slug":"package-pkg-not-found-in-importer","errorCode":null,"errorMessage":"Package \"${pkg}\" not found in \"${importer}\"","messagePattern":"Package \"(.+?)\" not found in \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slidev/node/vite/monacoTypes.ts","lineNumber":32,"sourceCode":"    resolveId(id) {\n      if (id.startsWith('/@slidev-monaco-types/'))\n        return id\n      return null\n    },\n\n    async load(id) {\n      if (!id.startsWith('/@slidev-monaco-types/'))\n        return null\n\n      const url = new URL(id, 'http://localhost')\n      if (url.pathname === '/@slidev-monaco-types/resolve') {\n        const query = new URLSearchParams(url.search)\n        const pkg = query.get('pkg')!\n        const importer = query.get('importer') ?? userRoot\n\n        const pkgJsonPath = await findDepPkgJsonPath(pkg, importer)\n        if (!pkgJsonPath)\n          throw new Error(`Package \"${pkg}\" not found in \"${importer}\"`)\n        const root = slash(dirname(pkgJsonPath))\n\n        const pkgJson = JSON.parse(await fs.readFile(pkgJsonPath, 'utf-8'))\n        let deps = Object.keys(pkgJson.dependencies ?? {})\n        deps = deps.filter(pkg => !utils.isMonacoTypesIgnored(pkg))\n\n        return [\n          `import \"/@slidev-monaco-types/load?${new URLSearchParams({ root, name: pkgJson.name })}\"`,\n          ...deps.map(dep => `import \"/@slidev-monaco-types/resolve?${new URLSearchParams({ pkg: dep, importer: root })}\"`),\n        ].join('\\n')\n      }\n\n      if (url.pathname === '/@slidev-monaco-types/load') {\n        const query = new URLSearchParams(url.search)\n        const root = query.get('root')!\n        const name = query.get('name')!\n        const files = await fg(\n          [","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/slidevjs/slidev/blob/0d798ace5828966d9f77f62094d5f7a971ad98f7/packages/slidev/node/vite/monacoTypes.ts#L14-L50","documentation":"Thrown by the `slidev:monaco-types-loader` Vite plugin while serving Monaco Editor type definitions for code blocks. When a slide's fenced code block imports a package, Slidev generates a virtual `/@slidev-monaco-types/resolve?pkg=<name>&importer=<dir>` request; the plugin uses vitefu's `findDepPkgJsonPath(pkg, importer)` to locate that package's package.json from the importer directory. If the dependency cannot be resolved from node_modules, it throws so Monaco doesn't ship broken/incomplete type info.","triggerScenarios":"A slide contains a code block importing a package (e.g. `import x from 'some-pkg'`); Monaco requests its types; the loader walks node_modules from the `importer` (defaults to `userRoot`) and `findDepPkgJsonPath` returns null. Common when the package is genuinely absent, is a bundled/inline type stub with no installed package.json, or when a monorepo hoisting layout puts the dep outside the resolver's search path.","commonSituations":"Authoring example code in slides that imports libraries never added to the deck project; using a monorepo workspace where the dependency is hoisted to a root that vitefu won't traverse from the slide's userRoot; importing a package whose package.json sits behind a symlink vitefu won't follow; TypeScript path-mapped aliases that have no physical node_modules entry.","solutions":["Install the missing package in the deck's userRoot: `npm i <pkg>` (or pnpm/yarn equivalent), then restart the dev server.","If the import is illustrative only and you don't want the real dependency, add the package name to Slidev's monaco-types ignore list so the loader skips it (the code already filters via `utils.isMonacoTypesIgnored`).","In a monorepo, ensure the dependency is resolvable from the Slidev `userRoot` directory (install at that workspace, not only at the repo root) so vitefu's upward walk finds it.","Double-check the spelling/ casing of the package in the code block and that it matches the installed package name exactly."],"exampleFix":"// before: code block imports a package that isn't installed\n```ts\nimport { z } from 'zod'\n```\n// after: install it so Monaco can resolve types\n//   pnpm add zod\n// or mark it ignored in slidev config if it is example-only:\n// slidev.config.ts -> monacoTypesIgnored: ['zod']","handlingStrategy":"validation","validationCode":"// Before relying on a package for Monaco types, verify it resolves from the\n// deck's userRoot using the same resolver the plugin uses:\nimport { findDepPkgJsonPath } from 'vitefu'\nasync function canResolvePkg(pkg: string, importer: string): Promise<boolean> {\n  return Boolean(await findDepPkgJsonPath(pkg, importer))\n}\n// if false, install the package or add it to monacoTypesIgnored.","typeGuard":"function isInstalledPackage(pkg: string, importer: string): Promise<boolean> {\n  return findDepPkgJsonPath(pkg, importer).then(Boolean)\n}","tryCatchPattern":null,"preventionTips":["Install every package your code blocks import in the deck's userRoot.","For example-only imports you don't want to ship, add the package name to Slidev's monaco-types ignore list.","In monorepos, install the dependency at the Slidev workspace so vitefu's upward node_modules walk finds it.","Avoid TypeScript path aliases for code shown in slides; Monaco resolves physical node_modules entries."],"tags":["slidev","monaco","dependency-resolution","node-modules","vitefu"],"backgroundTag":null,"analyzedSha":"0d798ace5828966d9f77f62094d5f7a971ad98f7","analyzedAt":"2026-08-12T17:10:56.221Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}