-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docusaurus 3.6.3: Typescript cannot find module @theme #10733
Comments
I have the same issue |
Thanks for reporting, this is related to #10694 (comment) I'll study your Grafana tools repo and see if I can find a better setup that doesn't break sites. @ahnpnl it can help if you also share a repro |
Hi, https://github.com/kulshekhar/ts-jest/tree/main/website you can use this repo and the failed PR is kulshekhar/ts-jest#4638 |
Thanks for the info and the link @slorber. So the current workaround would be the following in the websites tsconfig (as that is how it was previously):
|
I still think the change we did was right: our base TS config shouldn't explicitly restrict types, and keep TS default behavior. However, removing There are multiple solutions, such as:
But to me the root of the problem is due to the half-typed setup of your sites, mostly because you use JS for your config files instead of TS. By default, our init template imports theme/preset types automatically: https://github.com/facebook/docusaurus/blob/main/examples/classic-typescript/docusaurus.config.ts In particular:
As soon as you properly type your config file according to the preset you use, all the necessary ambient theme files will become available for typechecking. I think we should keep the current base TS setup, and instead you should improve your site's typesafety. So unless there's a good reason, I'm going to close this issue. Please let me know if this works for you. I thought about using |
Note, if you want to keep a JS config file, you can get the same benefit with JSDoc, that is now provided by default in our init template: /** @type {import('@docusaurus/types').Config} */
const config = {
...generalConfig,
url: 'https://grafana.com/',
baseUrl: 'developers/plugin-tools/',
plugins,
presets: [
[
'classic',
/** @type {import('@docusaurus/preset-classic').Options} */
({
docs: {
...presetsDocs,
routeBasePath: '/',
},
theme: presetsTheme,
blog: false,
}),
],
],
} Important: make sure to wrap the option object with extra |
@ahnpnl same for you. Your config is in TS, and you should rather import/use the preset type: import type {Config} from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';
const config: Config = {
title: 'My Site',
presets: [
[
'classic',
{
docs: {
},
blog: {
},
} satisfies Preset.Options,
],
],
}; Somehow I think it's a feature that Docusaurus doesn't typecheck in your case: it's a sign that your TS setup is not ideal, not typechecking preset options 😄 |
I see no reason not to move our configs to |
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clear
oryarn clear
command.rm -rf node_modules yarn.lock package-lock.json
and re-installing packages.Description
Updating docusaurus from 3.6.0 to 3.6.3 appears to break type aliasing (at least in our mono-repo). I cannot track this down but anything that imports from
@theme
doesn't resolve to what should betheme-classic
types anymore. I can fix it by adding the following totsconfig.json
which seems a bit strange for a minor update."compilerOptions": { "baseUrl": ".", + "types": ["@docusaurus/theme-classic"] },
I've tried bumping TS, removing global.d.ts, scaffolding a fresh docusaurus website with
npx create-docusaurus@latest docusaurus-website classic --typescript
and comparing files but I cannot figure it out.Reproducible demo
grafana/plugin-tools#1312
Steps to reproduce
renovate/docusaurus-dependencies
npm i
to install depsnpm typecheck
error TS2307: Cannot find module '@theme/*' or its corresponding type declarations.
errorsExpected behavior
For the type aliases to resolve correctly.
Actual behavior
Type aliases don't resolve resulting in lots of
error TS2307: Cannot find module '@theme/*' or its corresponding type declarations.
errors.Your environment
Self-service
The text was updated successfully, but these errors were encountered: