facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
54.07k stars 8.1k forks source link

[@docusaurus/plugin-client-redirects] `Redirect file creation error` on windows #10232

Closed axel7083 closed 1 week ago

axel7083 commented 2 weeks ago

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

When defining urls that are the same except uppercases, we are getting an error on windows machine

Reproducible demo

No response

Steps to reproduce

  1. on windows machine clone https://github.com/containers/podman-desktop
  2. run yarn to install dependencies
  3. run yarn website:prod

Expected behavior

build should work the same on windows and on linux

Actual behavior

[ERROR] Redirect file creation error for "~\podman-desktop\website\build\docs\Installation\windows-install\installing-podman-desktop-silently-with-the-windows-installer\index.html".

[ERROR] Error: Unable to build website for locale en.
    at tryToBuildLocale (~\podman-desktop\node_modules\@docusaurus\core\lib\commands\build.js:54:19)
    at async ~\podman-desktop\node_modules\@docusaurus\core\lib\commands\build.js:65:9
    at async mapAsyncSequential (~\podman-desktop\node_modules\@docusaurus\utils\lib\jsUtils.js:20:24)
    at async Command.build (~\podman-desktop\node_modules\@docusaurus\core\lib\commands\build.js:63:5) {
  [cause]: [Error: EEXIST: file already exists, open '~\podman-desktop\website\build\docs\Installation\windows-install\installing-podman-desktop-silently-with-the-windows-installer\index.html'] {
    errno: -4075,
    code: 'EEXIST',
    syscall: 'open',
    path: '~\\podman-desktop\\website\\build\\docs\\Installation\\windows-install\\installing-podman-desktop-silently-with-the-windows-installer\\index.html'
  }
}

The reason is because we define the following

{
  to: '/docs/installation/windows-install',
  from: [
    '/docs/installation/windows-install/installing-podman-desktop-silently-with-the-windows-installer',
    '/docs/Installation/windows-install/installing-podman-desktop-silently-with-the-windows-installer',
  ],
},

There is a small difference, the uppercase at Installation.

The error only appear when building on windows, in our pipeline, no issue raised.

Your environment

Self-service

slorber commented 1 week ago

This is most likely because your file system is case-insensitive, unlike your CI

The 2nd redirect file can only be created unless the file system is case sensitive and allow both files to exist.

What would you expect to happen, for both environments, in this case?

I'd recommend against emitting twice the file. Many hosts will support serving static files in a case-insensitive fashion and just emitting lower-case redirect files should be enough.

For example Netlify:

GitHub Pages:

I think some hosts like Vercel are case sensitive. But the truth is, you shouldn't use client directs with any host that support server redirects instead.

Server redirects are always a better option, and to my knowledge only GitHub pages do not support server directs, so the only good reason to use client directs is if you deploy to GitHub Pages (or similarly very limited host), which is case insensitive.

Note docusaurus serve is also case insensitive so if you use it for self-hosting, no need to duplicate your redirects.


For these reasons I'm going to close for now, but still curious to see what you expect from Docusaurus in this case.

I don't think we really need to fix anything here. At best we could ignore the error, or emit a more user-friendly error message.

But it looks good enough to me honestly, because you figured out that you had twice the same redirect already. The question is: why did you add twice the same redirect in the first place? Have you tried with only one redirect, and what motivated you to add a second redirect?

axel7083 commented 1 week ago

Thanks for the amazing explanation đź‘Ť !

I don't think we really need to fix anything here. At best we could ignore the error, or emit a more user-friendly error message.

Yes this is what I expect, having either a more friendly error, or ignore it.

But it looks good enough to me honestly, because you figured out that you had twice the same redirect already. The question is: why did you add twice the same redirect in the first place? Have you tried with only one redirect, and what motivated you to add a second redirect?

No idea; I arrived later after it was like this, and the person who did that is not here anymore.