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.

The serve command does not respect baseUrl

See original GitHub issue

🐛 Bug Report

If a site config has baseUrl set to anything but '/' such as when a site is meant for GitHub, the docusaurus serve command won’t work since build will add the baseUrl to links, but serve does not respond to it.

Have you read the Contributing Guidelines on issues?

Yes

To Reproduce

  1. Pick any project meant for deployment as a GitHub page that has a baseUrl set to some folder other than root, for example: baseUrl: '/docusaurus/'
  2. Check your package.json scripts to ensure you have the script entry "serve": "docusaurus serve".
  3. Run npm run serve -- --build. This will ensure you are building a fresh copy on every serve.
  4. Open your browser in the URL shown on the console by the previous command

Expected behavior

Site should open as it would when deployed

To see what should be expected,

  1. change the site config baseUrl to baseUrl: '/'
  2. run npm run serve -- --build.

Actual Behavior

The html for the initial page is displayed (or any page if you use the full address of the page) but all resources linked to from that page fail as they contain the baseUrl path. No CSS, images or scripts. Links don’t work.

Your Environment

From package.json:

  "dependencies": {
    "@docusaurus/core": "^2.0.0-alpha.61",
    "@docusaurus/preset-classic": "2.0.0-alpha.59",
    "clsx": "^1.1.1",
    "react": "^16.10.2",
    "react-dom": "^16.10.2"
  }

Chrome: Version 84.0.4147.125 (Official Build) (64-bit) (browser is not particularly relevant since you can see the buildUrl value inserted in the index.html anyway) nodeJS: v14.7.0 Ubuntu 20.04.1 LTS

Reproducible Demo

It is easier to pick any project the tester is familiar with than going through the trouble of setting up another one. Either add a subfolder to baseUrl to a project that doesn’t have one, or use one that does have it set.

Suggested fix:

Ensure serve command reads the baseUrl setting and strip it off the requests it gets.

Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Satyamcommented, Aug 17, 2020

@slorber , as an interim solution it works. My npm script now has

"serve": "docusaurus build --out-dir build/myDocs && docusaurus serve"

Just an additional warning: when it finishes the serve command announces that you can check the site at - Local: http://localhost:3000, which is misleading and confusing since it usually picks some build left over by some previous build that doesn’t work with serve. The actual address to be used is - Local: http://localhost:3000/myDocs

1reaction
anshulrgoyalcommented, Aug 17, 2020
 rewrites: [
        {source: `${props.baseUrl}:path`, destination: '/:path'},
      ],

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why are these tsconfig paths not working? - Stack Overflow
Changing baseUrl to "." and updating includes and paths makes no difference ( @client continues to work and @suir continues to not work). ......
Read more >
Building for Production - Vite
When it is time to deploy your app for production, simply run the vite build command. By default, it uses <root>/index.html as the...
Read more >
Switch between environments in Cypress - Filip Hric
The baseUrl attribute is used in .request() and .intercept() commands as well. This is better than using an env variable. For example, you...
Read more >
Configuration Reference | Vue CLI
This option is not respected by the cli-unit-jest plugin, because in jest, we don't have to transpile code from /node_modules unless it uses...
Read more >
Changelog - Cypress Documentation
The tsConfig build option is now respected for Angular component tests. ... Vite dev-server for component testing will not crash if user has...
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