Published `.d.ts` files import undeclared modules, so consumer types silently become `any` on non-hoisted installs
Node Version
22.23.2
Package Manager
pnpm
Package Manager Version
11.26.0
Strapi Version
5.54.0
Operating System
MacOS
Database
PostgreSQL
Javascript or Typescript
Typescript
Bug Description
Published @strapi/* packages ship .d.ts files that import modules their own package.json does not declare. In a consumer whose node_modules is not hoisted, those imports do not resolve, and the types they carry silently become any.
The visible symptom in consumer code is implicit-any errors that point at the consumer's own files, with nothing obviously wrong at the Strapi boundary:
Type '(props: ErrorProps) => any' is not assignable to type 'never'.
Type 'unknown' is not assignable to type 'never'.Page.Error is typed as returning any, and Core.MiddlewareHandler's context is unknown instead of a Koa context. Every prop type derived from React collapses the same way.
The cause is that TypeScript resolves a package's imports relative to where that package physically lives, and ignores NODE_PATH. When a package is linked from a store outside the consuming repo, the upward directory walk from its .d.ts never reaches the consumer's node_modules, so react resolves to the untyped react/index.js rather than to @types/react.
This has not surfaced before because two things hide it. A hoisted node_modules resolves the missing declarations by accident, and skipLibCheck: true — the default in Strapi's own generated tsconfig.json — suppresses the errors inside the .d.ts files themselves. It is visible to any consumer on pnpm's global virtual store (enableGlobalVirtualStore) or Yarn PnP.
One downstream repo hit 28 hard TypeScript errors across their Strapi app and all four of their plugins from this, and now carries 11 packageExtensions entries as a workaround.
Steps to Reproduce
Four files, then one command. This is self-contained and needs no Strapi app.
package.json{ "name": "strapi-types-repro", "private": true, "version": "1.0.0", "dependencies": { "@strapi/admin": "5.54.0", "@strapi/types": "5.54.0", "@strapi/logger": "5.54.0", "react": "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^6.30.3", "styled-components": "^6.1.13", "@types/react": "^18.3.2", "@types/react-dom": "^18.3.0", "@types/koa": "^2.15.2", "@types/lodash": "^4.14.197", "typescript": "5.9.3" } }Note that
@types/react,@types/koaand@types/lodashare installed at the consumer root. The problem is that the@strapi/*packages cannot see them.pnpm-workspace.yaml— these keys must go here. pnpm 11 ignores them in.npmrc.enableGlobalVirtualStore: true nodeLinker: isolated hoist: falsetsconfig.json—moduleResolution: Bundlermatches the profile Strapi's own packages are built with.{ "compilerOptions": { "target": "ESNext", "module": "ESNext", "moduleResolution": "Bundler", "lib": ["DOM", "DOM.Iterable", "ESNext"], "jsx": "react-jsx", "strict": true, "esModuleInterop": true, "skipLibCheck": false, "noEmit": true, "types": [] }, "include": ["src"] }src/probe.tsx— assigning tonevermakestscprint the type it actually inferred.import type { Core } from '@strapi/types'; import { Page } from '@strapi/admin/strapi-admin'; export const showPageError: never = null as unknown as typeof Page.Error; export const showCtx: never = null as unknown as Parameters<Core.MiddlewareHandler>[0];
Then:
$ pnpm install
$ readlink node_modules/@strapi/admin
../../../../../../../../../Users/me/Library/pnpm/store/v11/links/@strapi/admin/5.54.0/…/node_modules/@strapi/admin
$ npx tsc -p .Observed — 665 errors, of which 139 originate inside the @strapi/* packages:
src/probe.tsx: Type '(props: ErrorProps) => any' is not assignable to type 'never'.
src/probe.tsx: Type 'unknown' is not assignable to type 'never'.
react/index.js' implicitly has an 'any' type. ×495
react/jsx-runtime.js' implicitly has an 'any' type. ×112
lodash/lodash.js' implicitly has an 'any' type. ×12
koa/dist/koa.mjs' implicitly has an 'any' type. ×8
@strapi/logger :: TS2307: Cannot find module 'logform' or its corresponding type declarations.
@strapi/types :: TS2307: Cannot find module 'lodash' or its corresponding type declarations.
@strapi/types :: TS2307: Cannot find module 'undici' or its corresponding type declarations.
@strapi/admin :: TS2307: Cannot find module 'redux' or its corresponding type declarations.
@strapi/admin :: TS2307: Cannot find module 'redux-thunk' or its corresponding type declarations.
@strapi/admin :: TS2307: Cannot find module '@remix-run/router' or its corresponding type declarations.
@strapi/admin :: TS2307: Cannot find module 'formidable' or its corresponding type declarations.tsc --traceResolution shows koa landing on koa/dist/koa.mjs rather than on @types/koa/index.d.ts.
Setting hoist: true, or switching to npm/yarn defaults, makes all of it disappear — which is the point: the declarations are only correct by accident of layout.
Expected Behavior
Page.Error resolves to (props: ErrorProps) => Element, Core.MiddlewareHandler's parameter resolves to a Koa context, and tsc reports no errors originating inside the @strapi/* packages — the same result a hoisted install already gives today.
In other words, type checking a consumer should not depend on the consumer's node_modules layout, and skipLibCheck: false should be safe to turn on.
Additional information
I audited the built dist/**/*.d.ts of the core packages at 5.54.0 against their declared dependencies, rather than working from the errors alone. Three groups came out. dev-only means the entry is a devDependency — declared for the monorepo's own build, but never shipped to consumers.
1. @types/* referenced by the declarations but not declared
| Package | Missing |
|---|---|
@strapi/admin |
@types/react, @types/koa, @types/qs, @types/formidable; dev-only: @types/lodash, @types/json-logic-js, @types/passport-local |
@strapi/core |
@types/qs, @types/jsonwebtoken; dev-only: @types/koa, @types/lodash, @types/http-errors, @types/koa__router, @types/koa-compress, @types/json-logic-js |
@strapi/types |
dev-only: @types/koa, @types/koa__router, @types/lodash, @types/json-logic-js |
@strapi/utils |
@types/lodash; dev-only: @types/http-errors |
@strapi/permissions |
@types/lodash |
@strapi/database |
@types/lodash |
@strapi/email |
@types/react; dev-only: @types/koa |
@strapi/upload |
@types/react, @types/koa, @types/formidable |
@strapi/content-manager |
@types/react, @types/koa, @types/markdown-it, @types/codemirror5; dev-only: @types/lodash, @types/prismjs |
@strapi/content-type-builder |
@types/react, @types/koa, @types/json-logic-js |
@strapi/strapi |
@types/cli-progress; dev-only: @types/inquirer |
2. Real modules that leak into inferred return types. These come from tsc's inference rather than from any hand-written import, which is why they are easy to miss in review.
| Package | Missing | Currently resolves through |
|---|---|---|
@strapi/admin |
redux, redux-thunk |
react-redux + @reduxjs/toolkit |
@strapi/admin |
@remix-run/router |
react-router-dom@6 |
@strapi/admin |
reselect, msw |
hoisting |
@strapi/types |
undici |
declared by @strapi/core, used by @strapi/types |
@strapi/logger |
logform |
winston |
@strapi/upload |
reselect, redux, axios, @dnd-kit/utilities |
hoisting |
@strapi/content-manager |
redux |
hoisting |
@strapi/content-type-builder |
redux, axios, json-logic-js |
hoisting |
3. Cross-references between @strapi/* packages. @strapi/email, @strapi/upload and @strapi/content-type-builder reference @strapi/types in their published declarations and reach it only through the @strapi/admin peer. @strapi/admin and @strapi/content-manager reference @strapi/database the same way.
A possible shape for the fix, if it is useful — happy to defer entirely to whatever the team prefers:
@types/*as optional peer dependencies, so they deduplicate against whatever the consumer already has. Optional matters, otherwise JavaScript-only consumers get unmet-peer warnings.- Real runtime modules as plain
dependencies, pinned to whatever already resolves today, with no version bumps. @strapi/*cross-references as optional peers rather than dependencies, so a second copy of@strapi/typescannot appear. Two copies mean two TypeScript module identities, and adeclare module '@strapi/types/dist/...'augmentation would then target a file no build loads.
I have this applied on a branch and measured against the reproduction above: errors originating in these packages drop from 139 to 2, implicit-any from unreachable @types/* drops from 125 to 0, and a JavaScript-only consumer installed with strictPeerDependencies: true reports the same two pre-existing unmet peers as before and no new ones. I can open a PR whenever it is welcome.
Some practical notes for whoever picks this up:
- These packages are not published from a generated or templated
package.json, so the change belongs in each one.syncpackonly lintsprodanddevdependency types and ignores non-exact specifiers, so loose peer ranges do not tripyarn version:check. @types/codemirror5is an alias (npm:@types/codemirror@^5.60.15). Aliases are not reliably expressible inpeerDependencies, so that one wants to be a plain dependency, matching the existingcodemirror5alias.@strapi/coreand@strapi/adminboth reference@strapi/strapiin their declarations, which is circular and cannot simply be declared. Those two need a different approach.- The two errors that remain after the fix are in
@strapi/admin'sSubNav.d.ts(Cannot find name 'C') and follow from@strapi/design-system's own declarations. That is tracked at strapi/design-system#2046, which has the same problem in@strapi/design-system,@strapi/iconsand@strapi/ui-primitives, and additionally references@radix-ui/react-contextwithout declaring it. - #27249 is adjacent but solves a different problem: it declares per-workspace
devDependenciesso the monorepo itself builds under a strict linker, and does not change what the published packages declare. - Several things reported downstream turned out to be already declared at 5.54.0 and need no action:
json-logic-jsandpassport-localin@strapi/admin,@koa/routerandjson-logic-jsin@strapi/types,cli-progressin@strapi/strapi,prismjsin@strapi/content-manager,undiciin@strapi/core, and@radix-ui/react-contextin@strapi/admin.
Refiling #27744, which was auto-closed and routed to the feature-request flow. This is a defect in what is already published rather than a roadmap request, so I have moved the proposed fix down here and left the report itself to the symptom and the reproduction.
Confirmation Checklist
- I have checked the existing issues for duplicates.
- I agree to follow this project's Code of Conduct.
Source: strapi/strapi