next-plugin-preact icon indicating copy to clipboard operation
next-plugin-preact copied to clipboard

Cannot read property '__H' of undefined

Open faryar76 opened this issue 3 years ago • 8 comments

Hey :)

im testing preact with next.js and its ok. but when i tried to add some dependency(react-hook-form) and build "Cannot read property '__H' of undefined" appears!

  • preactjs + react-hook-form ---> working wihtout any errors

  • next.js + preactjs + react-hook-form --->Cannot read property '__H' of undefined

packages are latest version

faryar76 avatar Jun 16 '22 14:06 faryar76

Hi having the same issue, this is caused by webpack in next js importing different module files from preact/compat one from preact/compat/dist/compat.mjs.js and also from preact/compat/dist/compat.js

This plugin has some kind of "fix" for it, but looks like it's not working

sergeyzenchenko avatar Jun 16 '22 17:06 sergeyzenchenko

Hi having the same issue, this is caused by webpack in next js importing different module files from preact/compat one from preact/compat/dist/compat.mjs.js and also from preact/compat/dist/compat.js

This plugin has some kind of "fix" for it, but looks like it's not working

thank you for fast reply

what kind of fix ? its builtin? you have any solutions?

faryar76 avatar Jun 16 '22 21:06 faryar76

Same, getting error mentioned above when using npm run build. When using local dev server I'm also getting the "Error: Hook can only be invoked from render methods."

"next": "^12.1.6",
"next-plugin-preact": "^3.0.7",
"next-sitemap": "^3.0.4",
"next-themes": "^0.2.0",
"preact": "^10.8.2",
"preact-render-to-string": "^5.2.0",
"react": "npm:@preact/compat@^17.1.1",
"react-dom": "npm:@preact/compat@^17.1.1",
"react-ssr-prepass": "npm:preact-ssr-prepass@^1.2.0",
"sharp": "^0.30.3"

Tobeyforce avatar Jun 25 '22 15:06 Tobeyforce

temporary fix would be to disable esmExternals in next.config.js

experimental: { esmExternals: false, }

quadrifolia avatar Jun 27 '22 08:06 quadrifolia

Wow thanks @quadrifolia this fixes it for me!!!

kien-ngo avatar Jun 28 '22 16:06 kien-ngo

temporary fix would be to disable esmExternals in next.config.js

experimental: { esmExternals: false, }

Could you elaborate a bit on what this does? :)

Tobeyforce avatar Jun 29 '22 17:06 Tobeyforce

+1 on what exactly this fix is doing

bruceharrison1984 avatar Sep 04 '22 03:09 bruceharrison1984

I'm not sure if this fix is the cause of my problem, but I've had massive memory leaks when building uusing esmExternals: false.

Tobeyforce avatar Nov 28 '22 16:11 Tobeyforce