You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Typescript compilation error after swizzling #8226
I have read the console error message carefully (if applicable).
Description
After swizzling a component (eject + typescript), the project does not compile.
Reproducible demo
No response
Steps to reproduce
Create new typescript docusaurus npx create-docusaurus@latest my-website classic --typescript
cd .\my-website\
Swizzle component npm run swizzle @docusaurus/theme-classic DocSidebarItem/Link -- --typescript --eject
Compile npm run typecheck
Expected behavior
No errors
Actual behavior
src/theme/DocSidebarItem/Link/index.tsx:4:35 - error TS2307: Cannot find module '@docusaurus/theme-common/internal' or its corresponding type declarations.
import {isActiveSidebarItem} from '@docusaurus/theme-common/internal';
Your environment
Public source code:
Public site URL:
Docusaurus version used: 2.1.0
Environment name and version (e.g. Chrome 89, Node.js 16.4): node v16.14.0
Operating system and version (e.g. Ubuntu 20.04.2 LTS): Windows 10
@erickzhao we never documented anywhere add such type imports. Whenever you import from /src or /lib you tap into internals. I'm not against exposing more things publicly but we'd rather discuss your use-case for importing these on a separate issue.
We hit a similar issue when importing from @theme/Tabs in a custom page. There are no TS errors but the types of the props are not loaded for autocomplete (because they delegate to @docusaurus/theme-common/internal). Adding "moduleResolution": "Node16" to our tsconfig fixes it.
Reacted by Sebastien Ahkrin, Sébastien Lorber and Adrian Tam
This no longer reproduces on Docusaurus 4.0.0-canary-6972 (TypeScript 7.0.2), nor on 3.10.2 (TypeScript 6.0.3). With the reported steps (swizzle @docusaurus/theme-classic DocSidebarItem/Link -- --typescript --eject), npm run typecheck passes.
The error came from the v2 tsconfig (@tsconfig/docusaurus), whose default moduleResolution ignores package.json"exports", so subpaths like @docusaurus/theme-common/internal could not be found. Since Docusaurus 3.0, the TypeScript template extends @docusaurus/tsconfig (#9050), which uses "moduleResolution": "bundler" (#9258) and resolves these subpaths.
Minimal 4.0.0-canary-6972 TypeScript site using the template's tsconfig.json (extends @docusaurus/tsconfig)
DocSidebarItem/Link, DocSidebarItem/Category and Tabs ejected with --typescript; they import @docusaurus/plugin-content-docs/client and @docusaurus/theme-common/internal
A page using @theme/Tabs, with a @ts-expect-error proving its props are typed and not any (the case from the comments)
npm run typecheck exits with 0 errors, and the site builds
I also re-ran the same swizzle on 2.1.0 with @tsconfig/[email protected] and TypeScript 4.8.4: the TS2307 error from the issue still shows there. If you upgraded an older site and kept a tsconfig that extends @tsconfig/docusaurus, switch it to "extends": "@docusaurus/tsconfig" as in the current template.
Activity
slorber commentedon Oct 19, 2022
Hey,
It looks to me it is related to the package.json "exports" that we introduced recently.
Try this:
{ "extends": "@tsconfig/docusaurus/tsconfig.json", "compilerOptions": { "baseUrl": ".", + "moduleResolution": "Node16" } }Probably related to: tsconfig/bases#122
JontyMC commentedon Oct 19, 2022
Thanks that worked
erickzhao commentedon Dec 16, 2022
It seems like using
Node16for module resolution makes my Swizzle work but then causes some of my type imports to fail (Docusaurus 2.2.0):slorber commentedon Dec 22, 2022
@erickzhao we never documented anywhere add such type imports. Whenever you import from /src or /lib you tap into internals. I'm not against exposing more things publicly but we'd rather discuss your use-case for importing these on a separate issue.
targos commentedon Feb 7, 2023
We hit a similar issue when importing from
@theme/Tabsin a custom page. There are no TS errors but the types of the props are not loaded for autocomplete (because they delegate to@docusaurus/theme-common/internal). Adding"moduleResolution": "Node16"to our tsconfig fixes it.fix(docs): Fix typescript error
fix(docs): Fix typescript error
fix(docs): Fix typescript error
fix(docs): Fix typescript error
fix(docs): Fix typescript error
fix(docs): Fix typescript error
global-quick-tap-ms: original PR
fix(docs): Fix typescript error
fix(docs): Fix typescript error
fix(docs): Fix typescript error
fix(docs): Fix typescript error
fix(docs): Fix typescript error
fix(docs): Fix typescript error
fix(docs): Fix typescript error
fix(docs): Fix typescript error
Branch Creation
fix(docs): Fix typescript error
slorber commentedon Oct 16, 2026
This no longer reproduces on Docusaurus
4.0.0-canary-6972(TypeScript 7.0.2), nor on3.10.2(TypeScript 6.0.3). With the reported steps (swizzle @docusaurus/theme-classic DocSidebarItem/Link -- --typescript --eject),npm run typecheckpasses.The error came from the v2 tsconfig (
@tsconfig/docusaurus), whose defaultmoduleResolutionignorespackage.json"exports", so subpaths like@docusaurus/theme-common/internalcould not be found. Since Docusaurus 3.0, the TypeScript template extends@docusaurus/tsconfig(#9050), which uses"moduleResolution": "bundler"(#9258) and resolves these subpaths.Repro: https://github.com/slorber/docusaurus-repros/tree/issue-8226
tsconfig.json(extends@docusaurus/tsconfig)DocSidebarItem/Link,DocSidebarItem/CategoryandTabsejected with--typescript; they import@docusaurus/plugin-content-docs/clientand@docusaurus/theme-common/internal@theme/Tabs, with a@ts-expect-errorproving its props are typed and notany(the case from the comments)npm run typecheckexits with 0 errors, and the site buildsI also re-ran the same swizzle on 2.1.0 with
@tsconfig/[email protected]and TypeScript 4.8.4: theTS2307error from the issue still shows there. If you upgraded an older site and kept a tsconfig that extends@tsconfig/docusaurus, switch it to"extends": "@docusaurus/tsconfig"as in the current template.(AI-assisted)