withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.89k stars 2.49k forks source link

RedocStandalone component not rendering (whatwg-url does not provide an export named 'default') in DevMode #12425

Open mr-t-Durden opened 6 days ago

mr-t-Durden commented 6 days ago

Astro Info

Astro                    v4.16.12
Node                     v20.11.0
System                   macOS (arm64)
Package Manager          yarn
Output                   static
Adapter                  none
Integrations             astro-expressive-code
                         @astrojs/mdx
                         @astrojs/sitemap
                         @astrojs/tailwind
                         astro-icon
                         @astrojs/react

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Trying to render the ReactStandalone component within a Astro project does not render the OpenAPI spec but shows the console error:

[astro-island] Error hydrating /src/components/Redoc.tsx SyntaxError: The requested module '/node_modules/whatwg-url/lib/public-api.js?v=0f68177f' does not provide an export named 'default' (at index.mjs?v=0f68177f:4:8)

This issue is exactly the same as in #6656 which had been solved via #6933. Unfortunately there seem to be a different bug with Redoc #10815 which lead to reverting the fix in #10855 , which brings up the old error described above.

What's the expected result?

OpenApi Specs via RedocStandalone component does render properly within an Astro project.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-ekgxkc?file=package.json

Participation

ematipico commented 1 day ago

You might want to add the noExternal yourself. Does that fix the issue?

mr-t-Durden commented 1 day ago

Hi @ematipico , thank you for your message. I'm not sure how to test your proposal. Is this something I can setup in the Stackblitz Minimal Reproducible Example?

ematipico commented 1 day ago

You'll have to update your astro.config.mjs like this:


defineConfig({
    vite: {
        ssr: {
            noExternal: ["redoc"]
        }
    }
})

I tried it with your stackblitz, and it worked for me

mr-t-Durden commented 1 day ago

@ematipico Thank you for your explanations. Unfortunately I just had reduced the Astro version during your try. Sorry for the confusion. I updated to the latest version and applied your proposed changes. Unfortunately the error is still present running the dev command.

mr-t-Durden commented 1 day ago

Jus to point this out: The build command is running through and renders the correct Redoc output. Nonetheless not rendering with the dev command is a bit dangerous as one may fall into a pit trying to solve this during development, as I just did 😬 It would be great, if this could be fixed.