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

Seeing warnings about unsupported file type: undefined for SVG images #9715

Open
6 of 7 tasks
dabeeeenster opened this issue Jan 8, 2024 · 5 comments
Open
6 of 7 tasks
Labels
bug An error in the Docusaurus core causing instability or issues with its execution

Comments

@dabeeeenster
Copy link
Contributor

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

When running npm run build after upgrading to docusaurus 3.1.0 I have started seeing the following WARNING errors in the console:

[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/saas-architecture.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/saas-architecture.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/flagsmith-model.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/flagsmith-model.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/flagsmith-model.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/flagsmith-model.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/saas-architecture.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/saas-architecture.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/sdk-remote-evaluation.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/sdk-remote-evaluation.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/sdk-local-evaluation.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/sdk-local-evaluation.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/sdk-remote-evaluation.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/sdk-remote-evaluation.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/sdk-local-evaluation.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/sdk-local-evaluation.svg)

You can find the images referenced here: https://github.com/Flagsmith/flagsmith/tree/main/docs/static/img e.g. https://github.com/Flagsmith/flagsmith/blob/main/docs/static/img/self-hosted-architecture.svg

These are optimised SVG images but they are valid and display fine in browsers.

Reproducible demo

Flagsmith/flagsmith#3246

Steps to reproduce

  1. Run npm run build
  2. See warning about SVGs

Expected behavior

No warning should show as the images are valid

Actual behavior

Receive warnings [WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/saas-architecture.svg" can't be read correctly. Please ensure it's a valid image.

Your environment

Self-service

  • I'd be willing to fix this bug myself.
@dabeeeenster dabeeeenster 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 Jan 8, 2024
@slorber
Copy link
Collaborator

slorber commented Jan 8, 2024

Can you create 2 minimal runnable repros?

  • one should show that the warning was not there in 3.0.1
  • the other should show the warning appearing in 3.1.0

I doubt it's the upgrade that led this warning to appear, because the new release doesn't contain any code change related to this.

My believe is that this warning has likely always been there, when you reference svgs in markdown content.

I'd kindly ask you to invest time to qualify better this potential bug.

@dabeeeenster
Copy link
Contributor Author

Ah yes you are correct @slorber ! It was my clearing the build cache that caused the warnings to reappear. I'm still not clear why they are being thrown however? I believe the SVG files are valid?

@slorber
Copy link
Collaborator

slorber commented Jan 8, 2024

Ah yes you are correct @slorber ! It was my clearing the build cache that caused the warnings to reappear. I'm still not clear why they are being thrown however? I believe the SVG files are valid?

That's likely a bug related to using svg files using markdown image syntax.

CleanShot 2024-01-08 at 19 16 37@2x

We should probably find a way to read the dimensions of local svg files to apply them to the <img> tag, so that it doesn't produce layout shifts when the svgs load.

Hmm apparently our lib "image-size" is supposed to handle svgs as well, so it's probably a bug in this library.

https://github.com/image-size/image-size

Can you provide a sample SVG?
Can you try reading its dimensions with that lib?

  • If it works with the lib but not with Docusaurus, then report the bug to the lib. We'll wait for a fix and upgrade the lib once a fix is available.
  • If it works with the lib but not Docusaurus, then it's a Docusaurus bug.

@dabeeeenster
Copy link
Contributor Author

dabeeeenster commented Jan 8, 2024

OK yep https://gist.github.com/dabeeeenster/004e82c3e344707751f294c16d5ddf50 shows the error being thrown in that library - issue raised here.

@damageboy
Copy link

FWIW, I have the same issue with editable svg's saved with draw.io.

For now my solution is to add a build step that is invoked before yarn build:

# finds all .svg files and passes them to xargs to paraellelize
# svgo-ing them in groups of 10 (this avoids paying nodejs JIT time for every file)
fd -e svg -0 | xargs -0 -P $(nproc) -n 10 svgo                                                                                                              ─╯

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
@damageboy @dabeeeenster @slorber and others