Skip to content
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

hooks.mjs imports @latest version of preact for direct (and oldest) versions. #3074

Closed
1 task
vyushin opened this issue Mar 21, 2021 · 2 comments
Closed
1 task

Comments

@vyushin
Copy link

vyushin commented Mar 21, 2021

  • Check if updating to the latest Preact version resolves the issue

https://codesandbox.io/s/serverless-resonance-spus5

Describe the bug
Preact hooks script is importing latest version of preact for every version. It makes conflicts for instances.

To Reproduce

https://codesandbox.io/s/serverless-resonance-spus5?file=/index.html

Steps to reproduce the behavior:

  1. Open https://codesandbox.io/s/serverless-resonance-spus5?file=/index.html
  2. Change import version from latest to direct version (for example 10.5.13)
import { h, render } from "https://unpkg.com/preact@10.5.13?module";
import { useState } from "https://unpkg.com/preact@10.5.13/hooks/dist/hooks.mjs?module";
  1. Erorr in console
    image

Expected behavior
hooks.mjs shouldn't import latest version of preact for direct (and oldest) version. It should use the version actually requested

Incorrect:
image
image
image

@vyushin vyushin changed the title hooks.mjs always imports @latest version of preact hooks.mjs imports @latest version of preact for direct (and oldest) versions. Mar 21, 2021
@rschristian
Copy link
Member

So that's not actually something done here. preact/hooks doesn't necessarily depend on the latest version of preact. It only lists Preact v^10.0.0 as a peerDep:

"peerDependencies": {
"preact": "^10.0.0"
},
In this situation, it's up to Unpkg to choose how to supply that peer dependency, and I guess it chooses the latest version.

It might be possible to just tie the versions together, i.e., preact/hooks v10.5.13 has a peerDep on preact v10.5.13, but I don't know if that's going to pop up to cause issues somewhere.

@marvinhagemeister
Copy link
Member

The problem is that module resolution is broken in unpkg. See:

The issue has open for a long while over at unpkg and it's therefore probably unlikely that they'll fix it. So the only solution is to switch to a CDN that does follow the module spec. The current popular ones are either https://www.skypack.dev/ or https://npm.reversehttp.com/ .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants