Typescript compilation error after swizzling
Have you read the Contributing Guidelines on issues?
- [X] I have read the Contributing Guidelines on issues.
Prerequisites
- [X] I'm using the latest version of Docusaurus.
- [X] I have tried the
npm run clearoryarn clearcommand. - [X] I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages. - [X] I have tried creating a repro with https://new.docusaurus.io.
- [X] 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
Self-service
- [ ] I'd be willing to fix this bug myself.
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: https://github.com/tsconfig/bases/pull/122
Thanks that worked
It seems like using Node16 for module resolution makes my Swizzle work but then causes some of my type imports to fail (Docusaurus 2.2.0):
import type {
Sidebars,
SidebarItemDoc,
} from '@docusaurus/plugin-content-docs/src/sidebars/types';
@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.
