withastro / starlight

🌟 Build beautiful, accessible, high-performance documentation websites with Astro
https://starlight.astro.build
MIT License
5.02k stars 532 forks source link

Starlight is incompatible with the Astro build.format preserve option #1781

Closed lschierer closed 5 months ago

lschierer commented 6 months ago

What version of starlight are you using?

0.21.5

What version of astro are you using?

4.6.3

What package manager are you using?

pnpm

What operating system are you using?

Mac

What browser are you using?

Chrome

Describe the Bug

when I add the options

    trailingSlash: 'always',
    build: {
      format: 'preserve',
    },

to an existing otherwise working starlight project, it stops working with the error

13:16:42 [ERROR] Cannot read properties of undefined (reading 'addBase')
  Stack trace:
    at formatPath (/home/projects/withastro-starlight-7ibewh/node_modules/@astrojs/starlight/utils/createPathFormatter.ts:25:25)
    [...] See full stack trace in the browser, or rerun with --verbose.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-starlight-7ibewh?file=astro.config.mjs

Participation

delucis commented 6 months ago

Thank you for the bug report @lschierer! I think this is probably related to the 'preserve' setting — that was added to Astro after our logic for paths was added, so we’re likely not accounting for it in the createPathFormatter utility where that error is being logged.

Our formatting strategies account for the 'file' and 'directory' configurations, but not the newer 'preserve':

https://github.com/withastro/starlight/blob/be258c64d398173d061d5411ea4c9294860a74e7/packages/starlight/utils/createPathFormatter.ts#L15-L24