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

Regression bug on node imports #9326

Closed
1 task done
Omikorin opened this issue Dec 5, 2023 · 4 comments
Closed
1 task done

Regression bug on node imports #9326

Omikorin opened this issue Dec 5, 2023 · 4 comments
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) feat: markdown Related to Markdown (scope)

Comments

@Omikorin
Copy link

Omikorin commented Dec 5, 2023

Astro Info

Astro                    v4.0.1
Node                     v18.17.0
System                   Linux (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @astrojs/react
                         @pandacss/astro
                         @astrojs/mdx
                         @astrojs/sitemap

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

No response

Describe the Bug

I believe #8996 introduced a regression in these lines in the Code.astro which fails build from v3.4.4 to the latest version.

The best explanation will be with my screenshots of the build (you can check logs here -> Build packages -> @ark-ui/website).

v4.0.1:

image
image

Below I include a more clear build log from version v.3.4.4 which points directly to Code.astro

image
image

What's the expected result?

Successful build without a crash on node imports.

I added a minimal reproduction example as a branch of affected project because I encountered an issue here so I find it the best playground. When I have some free time, I'll make a minimal reproduction example on Stackblitz if you need.

Link to Minimal Reproducible Example

https://github.com/chakra-ui/ark/tree/build/astro-3.4.4-regression

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 5, 2023
@ematipico ematipico added feat: markdown Related to Markdown (scope) - P4: important Violate documented behavior or significantly impacts performance (priority) and removed needs triage Issue needs to be triaged labels Dec 6, 2023
@ematipico
Copy link
Member

@bluwy maybe this is something you might want to look at

@bluwy
Copy link
Member

bluwy commented Dec 6, 2023

I haven't looked at the repro, but the first few things I'd mention is that:

  1. Add shiki lang path compat #8996 has been removed in Astro 4, so it shouldn't be causing the issue.
  2. If Add shiki lang path compat #8996 was causing the issue in Astro 3, it's likely that you imported Code.astro in your client code? Could be barrel files causing it to snuck in.
  3. The warnings and errors you get in Astro 4 should also be the same cause, that you're importing node-only code in the client side somewhere.

@bluwy
Copy link
Member

bluwy commented Dec 7, 2023

The issue is due to this file:

https://github.com/chakra-ui/ark/blob/875023fc5cf5425bdad1d8fd1a085a8fed84e375/packages/website/src/components/docs/navigation/index.ts#L1-L4

The barrel file is exporting both Astro files and TSX files. Which means when you import TableOfContent (TSX component) and hydrate it, the barrel file gets bundled in the client alongside the nodejs dependencies, which it shouldn't get bundled.

On the usage-side in docs-layout.astro, you can fix it with this instead:

import { Footer, Navbar, Sidebar } from '~/components/docs/navigation'
import { TableOfContent } from '~/components/docs/navigation/table-of-content'

Barrel files should be avoided to prevent issues like this in general 😬

Also, I have to run pnpm update rollup to fix rollup/rollup#5259 from happening.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Dec 7, 2023
@Omikorin
Copy link
Author

Omikorin commented Dec 7, 2023

@bluwy thank you very much! It works :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) feat: markdown Related to Markdown (scope)
Projects
None yet
Development

No branches or pull requests

3 participants