Skip to content

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

@JulianCataldo

Description

@JulianCataldo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantViolate documented behavior or significantly impacts performance (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions