-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Cannot import hooks directly from unpkg #1961
Comments
Hi there! You can use the following imports to load hooks from unpkg successfully: import { h, render } from 'https://unpkg.com/preact@latest?module';
import { useState, useEffect } from 'https://unpkg.com/preact@latest/hooks/dist/hooks.module.js?module'; It's important to note that subpackage versioning does not work on unpkg. This is something I'd like to fix but haven't had the time to do. Working example: |
Hmm. I'm getting |
Hey @enjikaka here's a working application with unpkg imports if you want you can try/reproduce it there https://github.com/JoviDeCroock/Vanilla-Preact-Application |
@enjikaka I've changed the import in main to also use |
@Kanaye Ah, yes. Thanks! I assumed |
@developit In your example, how could we add htm into the mix? I tried multiple unpkg combination but couldn't make it works. (hooks + preact + htm) |
@developit Can you clarify: Is this a bug in unpkg, or a bug in preact? |
It's an issue with unpkg. If you're looking for a CDN in the meantime, I set one up that supports import maps and module concatenation: |
I found the bug in unpkg's github mjackson/unpkg#197 |
import { h } from 'https://unpkg.com/preact@latest/dist/preact.module.js?module'; Importing only this way, my webstorm could download the module and index the types. |
I just tried to make a new Codepen from scratch. Codepen loads from skypack by default, and simply importing
As I deduced from some searching on Preact's issue tracker, the issue is that the two modules are trying to import the same file, but are getting independent copies. Here's a working version. I thought I had changed the version hashes to match, but it looks like it's working now with different hashes. 🤷♂️ |
Here's another working version using esm.sh: https://codepen.io/chriscoyier/pen/MWZbEJR
I think Skypack is in deprecated/locked-down mode, which probably happened before preact had signals and all that? I dunno. Fred gave us a heads up on that a while back and suggested esm.sh. We have a plan to move to that but it's all part of a larger move and just isn't done yet. |
Hello,
hooks.module.js import from
preact
module, causing resolution failure when loading hooks as ES6 module. Should we import from preact.module.js in the same package instead?This is how I load
preact
andpreact/hooks
:The text was updated successfully, but these errors were encountered: