-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 read property '__H' of undefined when I try to use mjs-version of the "hooks" package #2690
Comments
Usually it should work when using imports like this: import { createElement as h, render, Component } from 'https://unpkg.com/preact@latest?module';
import { useState } from 'https://unpkg.com/preact@latest/hooks/dist/hooks.module.js?module'; (see https://github.com/JoviDeCroock/Vanilla-Preact-Application/blob/master/src/index.js#L1 ; https://github.com/JoviDeCroock/Vanilla-Preact-Application/blob/master/src/modules/home/index.js#L1 ) I guess this is a duplicate of #2564 #2439 #1961 #2571 Or am I missing your point? |
Yep, I seems to be right: there is an issue with the module you provided.
|
There's no issue for me when I run my example, could you fork it and change however the issue is caused? |
Yes, I figured out that hooks are working fine: https://jsfiddle.net/7mh09vx4/3/ |
I think, the problem is with the |
For future searchers, here is a simple snippet for importing the Preact as the native Ecmascript module:
import * as _Preact from 'https://cdn.skypack.dev/preact@10.4.7';
import * as _Hooks from 'https://cdn.skypack.dev/preact@10.4.7/hooks';
import htm from 'https://cdn.skypack.dev/htm@3.0.4';
export const html = htm.bind(_Preact.h);
export default _Preact;
export const Hooks = _Hooks; I developed a simple template (or an example, as you wish). It's an explanation how to set up skypack CDN's preact to be used with the Typescript. |
The same error. I think this is because hooks.mjs imports latest version of preact for every version. Make an issue #3074 |
@vyushin, the solution is not to use CDN you tried to use. ES modules feature they introduced is experimental. I have prepared a snippet, and It works just fine for me. Have you tried It? |
Having the same problem, when using it with next.js and the trace indicate webpack is import the module from preact/hooks/dist/hooks.module.js |
Was facing these exact issue with the typescript template. I was using the |
In case anyone else comes here that aliases react to preact/compat: It seems like at least with Next.js, preact/compat is not yet fully compatible with React 18. Installing React/React-DOM 17 fixed an error for me that was similar to this one which occurred when trying to navigate. |
my workaround with preact/hooks has been to delete the sub-package.json so that the top-level export map in Preact's root package.json is used instead in a type=module context. otherwise I get runtime issues due to mixed CJS / ESM module loading |
Having this error on pages that use next-mdx-remote. Any idea what causes this? It doesn't happen when I comment it out, then load the page, then uncomment it. (in dev mode) I think this is because it only happens on server renders, not on client renders. |
エラー:Cannot read property '__H' of undefined preactjs/preact#2690
If you are using a CDN such as esm.sh, you could be loading preact twice (check at your network panel) |
Same problem |
For everyone coming across this thread: This error means that you have multiple copies of Preact running at the same time in your project. This can be caused by various reasons. Please make sure you only use one copy of Preact. |
In case of importing through esm.sh like signals, be sure to specify external=preact so it is not loaded twice:
Thank you so much @marvinhagemeister |
Reproduction
Try to import hooks using from the mjs (with no bundlers) as described in the docs:
https://preactjs.com/guide/v8/getting-started/
https://preactjs.com/guide/v10/getting-started/#alternatives-to-jsx
The Preact itself is being imported fine, but I do not understand how should I import the
hooks
package properly.Steps to reproduce
Try to import hooks using
mjs
modules format like thisExpected Behavior
Hooks module is imported successfully
Actual Behavior
I see
error in the console and everything crashes (blank page).
The text was updated successfully, but these errors were encountered: