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

Raw Astro import fails when the imported component contains import.meta.*, only with Linux #5074

Closed
1 task
JulianCataldo opened this issue Oct 13, 2022 · 3 comments
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@JulianCataldo
Copy link

What version of astro are you using?

latest (1.4+)

Are you using an SSR adapter? If so, which one?

no

What package manager are you using?

pnpm

What operating system are you using?

debian/ubuntu/macos

Describe the Bug

it seems like importing an Astro file with the ?raw flag make rollup crash when there is an import.meta.* Vite magic string present inside this file.
It doesn't look like a project specific issue.
I was able to reproduce it with the GitHub CI (ubuntu) and a VPS with Debian. I enforce Node versions (nvm, and all…)
No problem whatsoever on macOS. These sort of problem are quite rare.

@astro-content/docs:build: Unexpected token (Note that you need plugins to import files that are not JavaScript)
@astro-content/docs:build: file: /home/runner/work/astro-content/astro-content/docs/src/layouts/Default.astro?raw:1:1458

https://github.com/JulianCataldo/astro-content/actions/runs/3235598248/jobs/5300250836

https://discord.com/channels/830184174198718474/1029770089249112084/1030145628753375364

So as a workaround, I'm loading Astro file raw content with the good ol' fs 😅
Just a wild guess but maybe Astro itself is doing things BEFORE Vite does it's raw import. So it's not totally raw.

Environment is the same for local / CI (enforced in workflow and NPM project).
Maybe it's the Astro parser? Maybe macOS / Ubuntu would show difference?

Log extract:


@astro-content/docs:build: 02:45:04 PM [build] output target: static
@astro-content/docs:build: 02:45:04 PM [build] Collecting build info...
@astro-content/docs:build: 02:45:04 PM [build] Completed in 545ms.
@astro-content/docs:build: 02:45:04 PM [build] Building static entrypoints...
@astro-content/docs:build: Unexpected token (Note that you need plugins to import files that are not JavaScript)
@astro-content/docs:build: file: /home/runner/work/astro-content/astro-content/docs/src/layouts/Default.astro?raw:1:1458
@astro-content/docs:build: 1: export default "---\nimport Document from '@julian_cataldo/astro-base/Document.astro';\nimport Body from '@julian_cataldo/astro-base/Body.astro';\nimport SEO from '@julian_cataldo/astro-seo/SEO.astro';\nimport Analytics from '@julian_cataldo/astro-analytics/Analytics.astro';\nimport Prefetch from '@julian_cataldo/astro-prefetch/Prefetch.astro';\nimport Tooltips from '@julian_cataldo/astro-tooltips/Tooltips.astro';\n/* ·········································································· */\nimport NavigationBar from '../app/NavigationBar.astro';\nimport LazyLoading from '../app/LazyLoading.astro' [...]"

I tried on stackblitz but I'm not able to reproduce this bug :(

Link to Minimal Reproducible Example

not able to reproduce it on stackblitz :(

Participation

  • I am willing to submit a pull request for this issue.
@matthewp
Copy link
Contributor

That's interesting, can you produce a stackblitz?

@matthewp matthewp added the - P4: important Violate documented behavior or significantly impacts performance (priority) label Oct 13, 2022
@JulianCataldo
Copy link
Author

JulianCataldo commented Oct 15, 2022

Minimal code with *.astro?raw + an import.* inside seems to work fine on Stackblitz, like on my local (macOS) dev environment.

I will try to minimize code interference and make a minimal repro. GH repo. instead of Stackblitz just to be sure.
You can close this maybe? And re-open if I confirm it's not a false flag, with an illustrative repro. alongside.

For information, here is the incriminated code, with comment alongside with the two alternative method, original + workaround.

https://github.com/JulianCataldo/web-garden/blob/7724d39db394ae9906f8893cafd20acf56093cd5/components/Testbed/Testbed.astro#L35

import.meta.glob('/**/*.{jsx,tsx,astro}', { as: 'raw' });

Also, I have to precise that it's the option { as: 'raw' }, not the ?raw flag in regular static import which I am using above, I mixed them up in previous explanations.

Thx!

@bluwy
Copy link
Member

bluwy commented Oct 17, 2022

This is a bug in Vite: vitejs/vite#10140. There's a PR in Vite vitejs/vite#9791 but it needs a rebase, but also worth implementing the esbuild replacement alternative. Closing this one for now.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2022
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)
Projects
None yet
Development

No branches or pull requests

3 participants