withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
45.82k stars 2.41k forks source link

"ReferenceError: fetch is not defined" on "pnpm create astro@latest" #11314

Closed casually-creative closed 2 months ago

casually-creative commented 3 months ago

Astro Info

`'astro' is not recognized as an internal or external command,
operable program or batch file.`

Describe the Bug

When running pnpm create astro@latest from any location on my machine, I receive ReferenceError: fetch is not defined. Same result with npm. Complete output below:

D:\SomeDirectory>pnpm create astro@latest

 astro   Launch sequence initiated.

   dir   Where should we create your new project?
         ./celestial-clusterfile:///C:/Users/Creative/AppData/Local/pnpm-cache/dlx/5ujifhftox4p5xbodgdmxvk2zm/1903fbd4063-d92c/node_modules/.pnpm/create-astro@4.8.0/node_modules/create-astro/dist/index.js:374
  const { version } = await fetch(`${registry}/${packageName}/latest`, {
                      ^

ReferenceError: fetch is not defined
    at file:///C:/Users/Creative/AppData/Local/pnpm-cache/dlx/5ujifhftox4p5xbodgdmxvk2zm/1903fbd4063-d92c/node_modules/.pnpm/create-astro@4.8.0/node_modules/create-astro/dist/index.js:374:23
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.14.0

My info:

What's the expected result?

A working set-up guide.

natenorberg commented 2 months ago

I'm hitting this too. I'm also hitting it with npm run dev on a project that was originally working for me. It builds on netlify and deploys fine, but not locally.

My info: macOS: 14.5 (Sonoma) node: v18.20.3 npm: 10.8.1

I'm surprised this isn't higher visibility. I wonder why this isn't breaking everyone

casually-creative commented 2 months ago

I got around it by just downloading an example from the github repo and using that as my starter project.

Princesseuh commented 2 months ago

I have honestly no idea how this could happen. fetch is a global available on any versions of Node >=18. Looking on the internet, it seems like some people reported this happening with corrupted installations, or funky installations where multiple versions of Node (including an outdated one) were used somehow

You two are the only reports of this happening, so I have no idea, really. Without a way to reproduce, there's no ways for us to potentially fix this (I have no idea what we'd fix, though), so I'll close this. Please report back if this happens again, but in the meantime, I'm puzzled.

My suggestion would be to reinstall Node, make sure everything is updated etc, and try again.

natenorberg commented 2 months ago

I fixed my issue and it has nothing to do with astro, but I'm adding this comment in case someone else ends up here.

I found out that I had --no-experimental-fetch set in my NODE_OPTIONS

Removing that option fixed the issue for me.