-
Notifications
You must be signed in to change notification settings - Fork 62
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
importing markdown and referencing import.meta.env
can crash the renderer if done in a certain order
#1056
Labels
- P2: has workaround
Bug, but has workaround (priority)
Comments
This seems to be an Astro compiler bug, where it's trying to hoist the imports, and it's incorrectly identifying the |
ascorbic
added
- P2: has workaround
Bug, but has workaround (priority)
and removed
needs triage
Issue needs to be triaged
labels
Jan 6, 2025
This is the transformed output: import {
Fragment,
render as $$render,
createAstro as $$createAstro,
createComponent as $$createComponent,
renderComponent as $$renderComponent,
renderHead as $$renderHead,
maybeRenderHead as $$maybeRenderHead,
unescapeHTML as $$unescapeHTML,
renderSlot as $$renderSlot,
mergeSlots as $$mergeSlots,
addAttribute as $$addAttribute,
spreadAttributes as $$spreadAttributes,
defineStyleVars as $$defineStyleVars,
defineScriptVars as $$defineScriptVars,
renderTransition as $$renderTransition,
createTransitionScope as $$createTransitionScope,
} from "astro/runtime/server/index.js";
import { Content } from "../test.md"
const $$Astro = $$createAstro();
const Astro = $$Astro;
const $$Card = $$createComponent(async ($$result, $$props, $$slots) => {
const Astro = $$result.createAstro($$Astro, $$props, $$slots);
Astro.self = $$Card;
const mode = import.meta.env.MOD
"
return $$render``;
}, 'Card.astro', undefined);
export default $$Card; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Astro Info
Describe the Bug
accessing an import.meta.env variable before a markdown loaded import causes inscrutable bugs. See stackblitz below for an example.
TLDR: This order does not error:
This order errors out:
In addition to
[ERROR] Unterminated string literal
I've also seen[ERROR] Expected "*/" to terminate multi-line comment
.If I had to guess I think that some of the Vite preprocessing for environment variables is leaking somehow, but the stack trace is all esbuild stuff that I'm not familiar with:
What's the expected result?
You should be able to access env vars and imports in any legal order without crashing the renderer.
I would submit a PR if I knew where to start on this one... the workaround of reordering imports seems fine for now, but because I don't know the root cause I don't know whether that will always work.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-ozuitpwy?file=src%2Fpages%2Findex.astro
Participation
The text was updated successfully, but these errors were encountered: