SilasBerger / teaching-website

My teaching website 👨‍🏫
https://teach.silasberger.ch
1 stars 0 forks source link

Add support for `@site/...` imports in `docusaurus.config.ts` / `builder` #2

Open SilasBerger opened 7 months ago

SilasBerger commented 7 months ago

@site/... imports work fine in React components and in .mdx files (thanks to intellij.config.js workaround for IntelliJ MDX plugin). However, they do not work in the docusaurus.config.ts and the whole builder part.

The @docusaurus/tsconfig file defines the @site path alias as follows:

"compilerOptions": {
  "paths": {
      "@site/*": ["./*"]
  },
}

It seems like that file doesn't apply to docusaurus.config.ts: Imports such as @site/src/builder/logger in docusaurus.config.ts are accepted (and even suggested) by the IDE, but during yarn run build, they yield the following error:

Cause: Cannot find module '@site/src/builder/logger'
Require stack:
- /Users/silas/repos/teaching-website/docusaurus.config.ts
    at loadFreshModule (/Users/silas/repos/teaching-website/node_modules/@docusaurus/utils/lib/moduleUtils.js:36:15)
    at loadSiteConfig (/Users/silas/repos/teaching-website/node_modules/@docusaurus/core/lib/server/config.js:35:62)
    ... 2 lines matching cause stack trace ...
    at async Command.start (/Users/silas/repos/teaching-website/node_modules/@docusaurus/core/lib/commands/start.js:44:19) {
  [cause]: Error: Cannot find module '@site/src/builder/logger'

Also note that the custom tsconfig.json file in the project root only applies for the IDE and is not used during compilation.

SilasBerger commented 7 months ago

What we know so far