Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Invalid URL while trying to build with sitemap not set to false #8116

Closed
6 of 7 tasks
chreniuc opened this issue Sep 19, 2022 · 6 comments · Fixed by #8159
Closed
6 of 7 tasks

TypeError: Invalid URL while trying to build with sitemap not set to false #8116

chreniuc opened this issue Sep 19, 2022 · 6 comments · Fixed by #8159
Labels
bug An error in the Docusaurus core causing instability or issues with its execution good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. hacktoberfest

Comments

@chreniuc
Copy link

chreniuc commented Sep 19, 2022

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

I'm using v2.1.0 and I've noticed that I get an error when I want to create a production build with sitemap not set to false, the yarn run start works with no issue, but when I run yarn run build I get a build error. If I set the sitemap option to false, it builds without errors. I use it as a blog only.

Reproducible demo

No response

Steps to reproduce

git clone https://gitlab.com/chreniuc/hreniuc-dev -b failed_build
cd hreniuc-dev
yarn install
yarn run build

Expected behavior

To build successfully.

Actual behavior

I'm receiving this error:

[ERROR] Unable to build website for locale en.
[ERROR] TypeError: Invalid URL
    at new NodeError (node:internal/errors:372:5)
    at URL.onParseError (node:internal/url:553:9)
    at new URL (node:internal/url:629:5)
    at new URL (node:internal/url:626:22)
    at normalizeURL (/path/node_modules/sitemap/dist/lib/utils.js:274:15)
    at SitemapStream._transform (/path/node_modules/sitemap/dist/lib/sitemap-stream.js:74:87)
    at SitemapStream.Transform._write (node:internal/streams/transform:184:23)
    at writeOrBuffer (node:internal/streams/writable:389:12)
    at _write (node:internal/streams/writable:330:10)
    at SitemapStream.Writable.write (node:internal/streams/writable:334:10)
    at /path/node_modules/@docusaurus/plugin-sitemap/lib/createSitemap.js:44:57
    at Array.forEach (<anonymous>)
    at createSitemap (/path/node_modules/@docusaurus/plugin-sitemap/lib/createSitemap.js:44:20)
    at Object.postBuild (/path/node_modules/@docusaurus/plugin-sitemap/lib/index.js:23:72)
    at /path/node_modules/@docusaurus/core/lib/commands/build.js:171:22
    at Array.map (<anonymous>)
    at buildLocale (/path/node_modules/@docusaurus/core/lib/commands/build.js:167:31)
    at async tryToBuildLocale (/path/node_modules/@docusaurus/core/lib/commands/build.js:38:20)
    at async mapAsyncSequential (/path/node_modules/@docusaurus/utils/lib/jsUtils.js:34:24)
    at async Command.build (/path/node_modules/@docusaurus/core/lib/commands/build.js:73:21)
[INFO] Docusaurus version: 2.1.0
Node version: v16.15.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Your environment

Self-service

  • I'd be willing to fix this bug myself.
@chreniuc chreniuc added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Sep 19, 2022
@slorber
Copy link
Collaborator

slorber commented Sep 28, 2022

🤪 hard to understand but I figured it out:

- url: 'hreniuc.dev',
+ url: 'https://hreniuc.dev',

I guess the config value you provide is fine and we should instead ensure that our normalization process will always normalize it to add the missing https:// protocol


Anyone want to contribute this?

(please directly submit a PR on your own if you want, don't ask if you can contribute and then go silent)

@slorber slorber added good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. hacktoberfest and removed status: needs triage This issue has not been triaged by maintainers labels Sep 28, 2022
@Josh-Cena
Copy link
Collaborator

normalize it to add the missing https:// protocol

I don't think that's a totally safe thing to do. We should just throw on anything that doesn't pass new URL() (which I thought we do already).

@slorber
Copy link
Collaborator

slorber commented Sep 29, 2022

Fine with both solutions. Agree it looks safer to ask user to always provide a protocol 👍

Also thought it was the case 😅 Joi is just a pain

@forgeRW
Copy link
Contributor

forgeRW commented Oct 1, 2022

I'd like to work on this so here's my PR #8159 for your review

@a11rew
Copy link

a11rew commented Oct 2, 2022

Ahh should have probably put in a heads-up that I was working on this

@Josh-Cena
Copy link
Collaborator

Yeah, it's always a good idea to at least give a heads-up—especially since it's October😅

forgeRW added a commit to forgeRW/docusaurus that referenced this issue Oct 8, 2022
    * fix: throw error for site URL in sub-path format

    * Also update unit tests to check error is thrown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. hacktoberfest
Projects
None yet
5 participants