Closed mayank99 closed 2 years ago
Thanks for opening an issue! Are there any logs you can share that might give more insight into what is going on?
Hmm, the deploy logs look normal ("your site is live"), and I couldn't find any runtime logs when I went into the "Edge functions" tab, possibly because it was a manual deploy using netlify deploy --build --prod
.
So I changed it to use auto deploy from git using the default settings and now it works!
I can close the issue but the manual deploy might still be broken. I was just following the instructions provided in the README: https://github.com/withastro/astro/blob/58b78229c103bfa4cf0260cefb6734b5918e90aa/packages/integrations/netlify/README.md?plain=1#L16-L22
I am reopening this because I'm still facing issues. The basic template was working fine but then I changed it to the portfolio
template and it broke again.
Error: TypeError: invalid URL: relative URL with a cannot-be-a-base base
Repo: https://github.com/mayank99/astro-netlify-edge Live deploy: https://new-astro-netlify-edge.netlify.app/
I have logs this time:
And the "Edge functions" tab has no logs.
Hi! I'm part of the team that works on Netlify Edge Functions - I'll look into what's causing this, and if it's something on the Netlify side of things.
The specific error message stems from Rust (see servo/rust-url
), and this snapshot test in Deno makes me wonder if it has to do with Deno (which Edge Functions uses for execution). I'll continue to do some digging.
One way to provoke this exact error message is to run this snippet in a Deno REPL:
import * as a from "data:application/javascript;base64,ZXhwb3J0IHsgYSB9IGZyb20gIi4vYS50cyI7Cg==";
This could be related to some Netlify-side bundling step. I'll continue looking into this after lunch.
Even easier way to show this error message, in Deno, Chrome, Firefox, or Safari: await import("data:application/javascript,import './foo.js'")
. The root cause is that you can not resolve a URL with a data URL as the base. You can see that this also throws in all environments:
new URL("./foo.js", "data:plain/text,xyz")
All that is to say, something in either Astro or the Netlify build pipeline is emitting a data URL that contains a relative specifier. This is invalid.
Could this also happen, when code contains import('./chunks/chunk.51537f84.mjs')
but ./chunks/...
isn't part of the Deno Subhosting bundle? This is part of what's generated by the repro, and I'm having the hunch that this could be related to what's happening here
Looking into this some more, the root cause are the dynamic imports: Deno Deploy and Netlify Edge Functions do not support dynamic imports. The error message is a bit of a red herring.
@natemoo-re This can be resolved in Astro by using Vite's import.meta.globEager
instead of import.meta.glob
.
Thanks @lucacasonato, I was aware that Cloudflare Workers did not support dynamic imports but I wasn't aware that is the case for Deno Deploy.
Is this something you're considering changing? I ask because fixing this on our end means using Rollup's inlineDynamicImports
which I worry might produce subtle bugs. That's what we'll need to do in the meantime, I guess.
@matthewp Yes, but this is unfortunately not a single toggle flag we can switch somewhere. It is a rather hard problem that we are trying to figure out a solution for.
Plan is to bundle these in the adapter using esbuild. SvelteKit does this: https://github.com/sveltejs/kit/issues/2963
Fixed in Deno Deploy but not Edge Functions, that's coming to another PR.
Closed by #3535 being merged.
@matthewp Thank you for releasing the fix. However, I'm getting a different error now on @astrojs/netlify@0.4.3
:
This is from the logs in "Edge functions" tab:
4:44:22 PM: ReferenceError: process is not defined
at netlify:bundle-combined:9548:13
at .netlify/edge-functions/entry.js (netlify:bundle-combined:10042:11)
at __init (netlify:bundle-combined:1074:62)
at netlify:bundle-combined:13875:1
4:44:22 PM: ReferenceError: process is not defined
at netlify:bundle-combined:9548:13
at .netlify/edge-functions/entry.js (netlify:bundle-combined:10042:11)
at __init (netlify:bundle-combined:1074:62)
at netlify:bundle-combined:13875:1
Worth noting that I'm still on astro@1.0.0-beta.31
because of #3466.
I can create a new issue if this looks unrelated.
This is likely a different issue. Deno doesn't define process
by default. If you need env vars you can use Deno.env
. If Astro wants users to have access to process.env
, your best bet is to add something like this in the wrapper:
globalThis.process ||= {
env: Deno.env.toObject()
}
What version of
astro
are you using?1.0.0-beta.31
Are you using an SSR adapter? If so, which one?
@astrojs/netlify/edge-functions
What package manager are you using?
npm
What operating system are you using?
Windows
Describe the Bug
I created a new astro repo with the portfolio template using
npm init astro -- --template portfolio
.Then I installed
@astrojs/netlify@0.4.0
and changed myastro.config.mjs
as follows:Then I pushed the changes to my repo. Netlify runs auto-deploy with its default settings. The site deploys "successfully" but results in
Error: TypeError: invalid URL: relative URL with a cannot-be-a-base base
as seen on https://new-astro-netlify-edge.netlify.app/See logs in my comment below.
Using the normal netlify functions adapter works perfectly fine.
Link to Minimal Reproducible Example
https://github.com/mayank99/astro-netlify-edge
Participation