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

[Docusaurus v3.4] index.html in static directory raises "Multiple assets emit different content to the same filename" error #10198

Open
6 of 7 tasks
Devon-White opened this issue Jun 4, 2024 · 5 comments
Labels
bug An error in the Docusaurus core causing instability or issues with its execution

Comments

@Devon-White
Copy link

Devon-White commented Jun 4, 2024

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

Using docusaurus start while having a index.html in the static directory will cause the following error:

Conflict: Multiple assets emit different content to the same filename index.html

Reproducible demo

https://codesandbox.io/p/devbox/kind-khorana-zg4f99?file=%2Fstatic%2Findex.html%3A5%2C8

Steps to reproduce

  1. Delete index.tsx in src/page
  2. create a index.html in the root of the static directory
  3. Observe failure

Expected behavior

For the html file to be added to the build like before this update, and to be able to serve a index.html file as the landing page.

Actual behavior

Error mentioned above occurs.

Your environment

No response

Self-service

  • I'd be willing to fix this bug myself.
@Devon-White Devon-White 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 Jun 4, 2024
@homotechsual
Copy link
Contributor

homotechsual commented Jun 5, 2024

Not a bug. We build to HTML pages. You cannot have an index.html file in static because we output a root index file. This is expected (and frankly required) behaviour. We have to output some kind of built index page to handle the scaffolding/app loading/container/routing. Even if you don't explicitly make one - we still have to write one for that purpose

@Devon-White
Copy link
Author

Devon-White commented Jun 5, 2024

Not a bug. We build to HTML pages. You cannot have an index.html file in static because we output a root index file. This is expected (and frankly required) behavior. We have to output some kind of built index page to handle the scaffolding/app loading/container/routing. Even if you don't explicitly make one - we still have to write one for that purpose

Understood, this is however a recent behavior as we have had a site since Docusaurus v2 and have handled the index page this way up until this version. We will look into swapping our approach if this is now expected.

Edit: A docusaurus build will also not throw this error, but instead links to / will throw a broken link error instead.

However, in the navbar config you can set like such do avoid the broken links:

  themeConfig:
    /** @type {import('@docusaurus/preset-classic').ThemeConfig} */
    ({
      // Replace with your project's social card
      image: 'img/docusaurus-social-card.jpg',
      navbar: {
        title: 'My Site',
        logo: {
          alt: 'My Site Logo',
          src: 'img/logo.svg',
          href: "pathname:///"
        },

Using the pathname protocol will allow you to correctly be redirected back to the index.html

Now the build will complete, and all links work.

Blumlaut added a commit to zaphosting/docs that referenced this issue Jul 16, 2024
this causes the development build to fail (facebook/docusaurus#10198)
fgalz pushed a commit to zaphosting/docs that referenced this issue Jul 18, 2024
* fix(voucherContext): handle errors in fetch

* refactor: remove index.html

this causes the development build to fail (facebook/docusaurus#10198)

* fix(validate): dont fail if file was deleted

* refactor(voucherContext): code cleanlyness

taken from #1277 (comment)
@Josh-Cena
Copy link
Collaborator

Hmmm. If you don't have a pages/index.tsx, I don't think we would emit build/index.html, so there shouldn't be duplicate assets.

@slorber
Copy link
Collaborator

slorber commented Jul 19, 2024

`Using docusaurus start while having a index.html in the static directory will cause the following error:``

During docusaurus start this is normal because we don't use SSR and we have to build/serve an initial entrypoint that is by default index.html

CleanShot 2024-07-19 at 13 32 43

https://webpack.js.org/plugins/html-webpack-plugin/

Afaik this file is served from memory when using the dev server.

We could probably do something but I'm not sure what makes sense. Do you expect Docusaurus dev server to start on http://localhost:3000/docs/myDoc for example?

I'm surprised this ever worked in v2. This behavior probably broke a long time ago already.

Maybe we could generate a random index name, and use this in devServer.historyApiFallback ?

@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Jul 19, 2024
@Devon-White
Copy link
Author

Devon-White commented Jul 29, 2024

We could probably do something but I'm not sure what makes sense. Do you expect Docusaurus dev server to start on http://localhost:3000/docs/myDoc for example?

I'm surprised this ever worked in v2. This behavior probably broke a long time ago already.

For additional context, this remains working on Docusaurus version 3.3.2, which is the version our site is currently running. Upon upgrading to the next version, 3.4, is where you begin to experience this failure.

Hmmm. If you don't have a pages/index.tsx, I don't think we would emit build/index.html, so there shouldn't be duplicate assets.

I was also in this mindset of thinking, that the index.html file should just work (like previously) if there is not a pages/index.tsx file.

Maybe we could generate a random index name, and use this in devServer.historyApiFallback ?

I'm not sure what the best solution here would be, but this feels like it would make sense.

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
Projects
None yet
Development

No branches or pull requests

4 participants