-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
can't use env in Netlify edge runtime #254
Comments
It's unclear to me if it's best way to solve this, but this can be addressed with following: In adapters/packages/netlify/src/index.ts Lines 231 to 254 in f14f4d7
have and finally adjust bundling config ( adapters/packages/netlify/src/index.ts Lines 259 to 269 in f14f4d7
node:process as with current configuration it would fail (likely due to neutral platform being used). In my quick test I just added node:process as external and this resulted in successful deploy with being able to use both import.meta.env and process.env in my test middleware.
Wether this is best way to actually fix it or not is a bit TBD, but seems like what is needed is to make Another way (might be more idiomatic way to provide global than above) is to use |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When using Netlify's Edge Runtime, Astro compiles
import.meta.env.FOO
toprocess.env.FOO
, butprocess.env
doesn't exist for that runtime.How I found this
astro build
adds the Astro component runtime to the site's middleware stack if both (a) the middleware and (b) a.astro
Page or Componentimport
the same shared library fromsrc/lib/
, even if that library has nothing to do with Astro or HTML.In b09bfe5a, the
middleware.ts
shares nothing with the*.astro
files.process.env
does not appear in the compiledmiddleware.mjs
. The compiledmiddleware.mjs
is 56710 bytes. It includes thecookie
andastro/dist/core
modules.In 4551a260, the
middleware.ts
andCard.astro
share an import, though the import is pure JS and unrelated to Astro. This import causes the compiledmiddleware.mjs
to gain 66721 bytes, 1600 new lines, and thecssesc
,kleur
,html-escaper
, andclsx
packages. Most notably, it adds aprocess.env
reference that breaks the Netlify build.In 4fba3cf5, I show that just adding an
import.meta.env.NODE_ENV
reference to the middleware is enough to break the Netlify build.I get this in my site's logs, though the line numbers don't match up with what's compiled here:
What's the expected result?
The the middleware doesn't reference any Astro components or pages, the compiled middleware code should not be affected by
*.astro
files importing the same files that it does. The runtimes should be isolated.According to the Netlify Edge Functions docs, Astro should probably compile those references to
Netlify.env.get
.Link to Minimal Reproducible Example
https://github.com/jamesarosen/astro-broken-middleware-demo
Participation
The text was updated successfully, but these errors were encountered: