-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
🐛 BUG: fetch
is unavailable until it isn’t
#1106
Comments
This is definitely a bug. Should be as simple as injecting isomorphic-fetch into all |
There is an article in the Astro documentation: Data Fetching#using-fetch-outside-of-astro-components. Add |
If anyone wants to work on this, it's probably just a matter of adding code to the transform step here: https://github.com/snowpackjs/astro/blob/d0e7fcfc0652c8e5b6af0b584838b605efb92a8a/packages/astro/snowpack-plugin.cjs#L27 If the file is |
Actually, the above is not a good solution, this will also affect frontend code! Probably the simple way is better and just add |
Should the fix be: I believe that a) would be fun and convenient, but b) -- having to import fetch -- wold be consistent with the rest of the node. As @itday mentions above, this already seems expected in the documentation. (Tangentially, deno has built-in 'fetch'. In this case, a) would be consistent. I wonder if there's been any thought toward selecting build-time environment: e.g. |
@johnhenry Global fetch was already accepted via the RFC process here: #410 . So this is a bug. The solution here is to make |
Here's a quick solution: f22a1cc |
Fixed in #1406! |
What package manager are you using?
npm
What operating system are you using?
Mac
Describe the Bug
Within the header of an
.astro
file, external.js
files cannot usefetch()
.Example
/src/pages/index.astro
:/src/fetched.js
:/public/metadata.json
:However, if I move the
const fetched_metadata
logic out of/src/fetched.js
and into/src/pages/index.astro
it will work.And then, if I undo that change, it will keep working!
It’s as if using
fetch
is not allowed in external.js
files, until it gets used in an.astro
file, at which point it gets put into the global scope and becomes available to the.js
files or something.Steps to Reproduce
npm init astro
.Link to Minimal Reproducible Example (Optional)
https://github.com/jonathantneal/astro-fetch-outside-astro-issue
The text was updated successfully, but these errors were encountered: