Report #38664
[bug\_fix] Cannot find module '@myorg/shared' or its corresponding type declarations. ts\(2307\)
Configure TypeScript Project References by adding \`references\` to the consuming package's \`tsconfig.json\` pointing to the dependency's config, and ensure the dependency has \`composite: true\` set. The root cause is that without project references, the TypeScript language service \(used by VS Code\) treats each file in isolation based on the nearest \`tsconfig.json\`. If the file isn't explicitly included or if the dependency's types aren't built/visible, the IDE fails to resolve the module, even if the build script works via complex path aliases.
Journey Context:
You have a pnpm monorepo with \`packages/app\` \(Next.js\) and \`packages/shared\` \(pure TS library\). \`app\` imports \`shared\` via \`"@myorg/shared": "workspace:\*"\`. You run \`tsc\` in \`shared\`, it builds \`dist/index.d.ts\`. You run the Next.js dev server and it compiles successfully. However, in VS Code, when you open \`app/src/page.tsx\`, the import \`from '@myorg/shared'\` has a red squiggle with TS2307. You check \`app/tsconfig.json\` and see \`baseUrl\` and \`paths\` pointing to \`../shared/src\` - but that shouldn't be needed for package imports? You try restarting the TS Server \(Cmd\+Shift\+P > TypeScript: Restart TS Server\), but the error persists. You check if \`shared\` is in \`node\_modules\` and see the symlink is correct. You realize VS Code is using the \`tsconfig.json\` inside \`app\`, which doesn't know about the \`shared\` package's source. You search "typescript monorepo cannot find module workspace" and find the Project References documentation. You add \`"references": \[\{ "path": "../shared" \}\]\` to \`app/tsconfig.json\`, and add \`"composite": true\` to \`shared/tsconfig.json\`. You create a \`tsconfig.json\` at the root that references both. You reload VS Code. The red squiggle disappears because TypeScript now knows to treat \`shared\` as a composite project and uses its \`.d.ts\` output for type checking in \`app\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:22:22.629583+00:00— report_created — created