question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"You are trying to create client-side redirections to paths that do not exist" to folders without trailing slash

See original GitHub issue

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I’m using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

For paths to folders without a trailing slash, hosts will typically 302 redirect to the path with the slash

e.g. https://docs.sheetjs.com/docs/getting-started redirects to https://docs.sheetjs.com/docs/getting-started/

@docusaurus/plugin-client-redirects does not seem to be aware of this behavior for folders that have subfolders.

This redirect works

        { from: '/docs/installation', to: '/docs/getting-started/' }, // works

This redirect elicits the error mentioned in the title:

        { from: '/docs/installation', to: '/docs/getting-started' }, // elicits error

The fact that it works for leaf folders that only have index.html suggests this is a bug in the redirect scanner:

        { from: '/docs/example', to: '/docs/getting-started/example' }, // this works, even though `example` is a folder

Reproducible demo

https://github.com/SheetJS/docs.sheetjs.com

Steps to reproduce

git clone --depth=1 https://github.com/SheetJS/docs.sheetjs.com
cd docs.sheetjs.com/docz
npm i
npm run build ## note: this should work
sed -I '' "s#started/'#started'#g" docusaurus.config.js
npm run build ## this will fail with the aforementioned error

If the sed command fails, the edit is in docusaurus.config.js:

       redirects: [
         { from: '/docs/example', to: '/docs/getting-started/example' },
-        { from: '/docs/installation', to: '/docs/getting-started/' },
+        { from: '/docs/installation', to: '/docs/getting-started' },
       ]
     }]

Expected behavior

It should create the redirect

Actual behavior

[ERROR] Error: You are trying to create client-side redirections to paths that do not exist:

The path in question is not listed in the valid paths

Your environment

No response

Self-service

  • I’d be willing to fix this bug myself.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SheetJSDevcommented, Aug 28, 2022

In a structure like:

/docs/index.md
/docs/foo/index.md
/docs/foo/bar.md

When trailingSlash is undefined, the routesPaths key exposed to in the postBuild props is:

[
  "/docs/",
  "/docs/foo/",
  "/docs/foo/bar"
]

Those paths are used in the validation.

One way to resolve the issue without disrupting other plugins is to add both slash variants to the validation.

https://github.com/facebook/docusaurus/blob/4b5a47ba37ffdfbcf46e23790ff0cfe6c4745e14/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts#L81

const allowedToPaths = pluginContext.relativeRoutesPaths.flatMap(x => { const y = x.replace(/\/+$/, ""); return [y, y + "/"] });
0reactions
slorbercommented, Aug 31, 2022

Happy to review your PR

@slorber The site started from the default config (npx create-docusaurus@latest). The default site does not include the trailingSlash setting. If it is strongly encouraged to use a default setting, should the default site include some trailingSlash setting?

We recommend an explicit trailing slash, but only for Github Pages users, not all users.

I wouldn’t recommend GitHub pages in the first place, Vercel/Netlify are much better alternatives and you don’t always need to use the trailingSlash setting with those.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Integrated handling of trailing slashes in Gatsby #34205
A nuance here is that we don't explicitly call out the presence of automatic redirects when using the trailingSlash setting.
Read more >
Bug in non-trailing slash rewrite
The first and recommended solution is make that redirect rule a “rewrite” rule be changing the HTTP status code used from 200 to...
Read more >
How can I configure IIS to serve directories without trailing ...
Now all requests with a trailing slash get it removed, IIS no longer performs 301 redirects to add back the slash, the client...
Read more >
Gatsby: to slash or not to slash?
Here comes the reason you should use trailing slashes on Gatsby: the path string passed to createPage() becomes a directory, and the resulting ......
Read more >
Trailing Slash - next.config.js
You can configure this behavior to act the opposite way, where urls without trailing slashes are redirected to their counterparts with trailing slashes....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found