esm-dev / esm.sh

A fast, smart, & global CDN for modern(es2015+) web development.
https://esm.sh
MIT License
3.08k stars 147 forks source link

Broken types for react/jsx-runtime causes deno to keep trying to download it #550

Closed KyleJune closed 1 year ago

KyleJune commented 1 year ago

The import map has the following entries for react. It tries pinning to 18.2.0 but the types version ends up being different.

    "npm/react": "https://esm.sh/react@18.2.0?target=deno&pin=v110",
    "npm/react/jsx-runtime": "https://esm.sh/react@18.2.0/jsx-runtime?target=deno&pin=v110",
    "npm/react/jsx-dev-runtime": "https://esm.sh/react@18.2.0/jsx-dev-runtime?target=deno&pin=v110",

The deno.jsonc file has the following compiler options for deno to use the jsx-runtime.

  "compilerOptions": {
    "lib": ["esnext", "dom", "dom.iterable", "dom.asynciterable", "deno.ns"],
    "jsx": "react-jsx",
    "jsxImportSource": "npm/react"
  },

You can reproduce the issue by checking out the github repository linked at the top of this issue and running the command deno task dev. Every time the application runs or reloads, it ends up trying to download the types again.

Evidence

In the following video, you can see that each time the application runs it downloads the react types multiple times.

https://user-images.githubusercontent.com/3241653/226081510-155fcfdb-f429-427a-9578-e0db98c82f3d.mp4

These are the URLs you can see it repeatedly downloading.

https://esm.sh/v110/@types/react@^18/jsx-runtime~.d.ts https://esm.sh/v110/@types/react@18.0.26/jsx-runtime~.d.ts

The first url redirects to the second. Then the second fails with a 522 error from cloudflare. You can see that in the following screenshot of dev tools.

image

Additional info

ije commented 1 year ago

not sure what happened, but i just re-deployed the CF worker, now it works. fyi, i added this URL in the checker script:

Screenshot 2023-03-18 at 12 15 35
KyleJune commented 1 year ago

It appears that I still have an issue where it keeps re-downloading it like shown in the video even though the links work in the browser for me. I'm not sure why, maybe that's a deno issue.

When I download the v110 file, it looks right, it's just a file that imports './index.d.ts'. But if I look at the response in firefox dev tools, it shows a base64 representation of the file. I'm not sure if it's related but maybe that's why deno isn't able to use it now that the URL works.

image image

Ly8gRXhwb3NlIGBKU1hgIG5hbWVzcGFjZSBpbiBgZ2xvYmFsYCBuYW1lc3BhY2UKaW1wb3J0ICcuL2luZGV4LmQudHMnOwo

I tried updating to v111 to see if that works but it fails like v110 was for me before.

https://esm.sh/v111/@types/react@^18/jsx-runtime~.d.ts

image

KyleJune commented 1 year ago

Github won't let me re-open the issue but I think it should be re-opened.

ije commented 1 year ago

seems the CF worker has issue with R2, i switch to KV storage for these .dts files

ije commented 1 year ago

finally i found CF worker can not handle origin server redirect correctly, fixed this issue after adding redirect: manual

KyleJune commented 1 year ago

I've confirmed your change resolved the issue. It doesn't keep trying to download it again each time I run the script anymore. Thank you

ije commented 1 year ago

thanks for reporting, a huge help