-
-
Notifications
You must be signed in to change notification settings - Fork 544
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
Throws on reading import.meta.env.BASE_URL
in Deno environment
#1387
Comments
Thanks for the issue @ben-laird!
Officially, Astro does not support building with Deno (only deploying to a Deno server environment), so not sure how easy this will be to fix (I’ve never used Deno personally) — and may even need fixing further upstream in Vite as mentioned above. |
After a quick read of Deno's docs, |
It looks like Vite officially supports Deno, so if you can create a minimal reproduction that shows the |
I made a minimal reproduction using pure Vite, no other frameworks, and when running Even funnier, when I changed that offending file in the Starlight minimal repro to use On top of that, it's not even that Vite/Deno doesn't have access to environment variable logic, because the dev script in the Starlight minimal repro runs with all Deno permissions allowed (the -A flag); apparently whether it does or not doesn't matter, because in the Vite minimal repro the I don't even know if this is an upstream issue, because it seemingly does not reside with Vite. |
Yeah, Starlight depends on |
It's currently failing in Deno because our env handling is referencing
Astro currently doesn't explicitly support Deno, so I think this isn't exactly a bug. There's likely more that needs tweaking if we want to get proper Deno support working. |
Can confirm this is a problem in Astro, not in Deno or Vite. I made another minimal reproduction, this time using only Astro. When running the dev server with Deno (using Here's a slice of the file where I invoked <!-- src/pages/index.astro -->
<!-- ... -->
<h1>Welcome to <span class="text-gradient">Astro</span></h1>
<p class="instructions">
To get started, open the directory <code>src/pages</code> in your project.<br
/>
<strong>Code Challenge:</strong> Tweak the "Welcome to Astro" message
above.
</p>
<!-- <p>import.meta.env.BASE_URL is {import.meta.env.BASE_URL}</p> -->
<!-- ^ This throws the same error, even when commented out -->
<!-- ... --> Hopefully this helps! Should I file an issue with Astro proper and use this minimal reproduction in my issue? |
Thanks for the clarification @bluwy — appreciate it! And thank you for all the digging @ben-laird 💖 @ben-laird I think the team might be happy to merge small, low maintenance PRs that improve compatibility, but until Astro decides official Deno support is required, I guess they’re unlikely to take on long-term maintenance ensuring stability (this would require running test suites in Deno etc. and team members dogfooding Astro in Deno, so it’s not a small task). As such, issues will also likely be closed as Deno support would be considered a feature request not a bug. Probably the best path would be to chime in on the existing feature request — withastro/roadmap#97 — although someone like yourself who is a keen user would be invaluable in figuring out further wrinkles. If I follow @bluwy’s suggestions, you might have some luck injecting that Given anything that would need changing to fix this would be upstream in Astro, I hope you don’t mind me closing this — unfortunately not much Starlight can do just yet. |
No offense taken on closing the issue, it really was an Astro thing anyways. I'll see what I can do on pushing for more dedicated Deno support, although I understand the commitment that would require, what with test suites and dogfooding and other things. I've tried injecting |
I came across this problem too, wanting to run a small script to do some thing where I want that script to import some tooling I build for my astro site. I ended up making it work like this (while also having to add .ts to all imports along along the way, which seems to work with no issues for astro): let env;
if (Object.hasOwn(globalThis, "Deno")) {
// hide from vite's analysis
const url = Math.random().toString().slice(100)
+ "https://deno.land/std@0.216.0/dotenv/mod.ts";
const { load } = await import(url);
env = await load();
} else {
env = import.meta.env || process.env;
} this also meant adding a |
What version of
starlight
are you using?^0.16.0
What version of
astro
are you using?^4.2.1
What package manager are you using?
pnpm
What operating system are you using?
Mac
What browser are you using?
Safari
Describe the Bug
Context
I'd like to use Starlight to make a docs site for a library I've published, but my repo uses Deno instead of Node, and I'd like to keep the docs site and the library code in the same repo.
Reproduction
deno task dev
(currently using Deno 1.39.4)https://localhost:4321
Cannot read properties of undefined (reading 'env')
Terminal logs:
Full stack trace:
Erroring file:
Expectation
Simply, this reproduction repo should not throw any errors.
Note I'd like to submit a PR for this issue (this is a great project and I'd love to help), although I have very little idea where the error is truly happening, what with Deno, Vite, Astro, and Starlight all underpinning my code; I'm going to leave the Participation checkbox unchecked for now. In addition, I'm still fairly new to open source contributions, so I don't want to degrade the codebase in any way.
Thanks so much for your help!
Link to Minimal Reproducible Example
https://github.com/bug-squashing/starlight-u1
Participation
The text was updated successfully, but these errors were encountered: