preactjs / next-plugin-preact

Next.js plugin for preact X
394 stars 9 forks source link

Cannot read property '__H' of undefined #61

Open faryar76 opened 2 years ago

faryar76 commented 2 years ago

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!

packages are latest version

sergeyzenchenko commented 2 years ago

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

faryar76 commented 2 years ago

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?

Tobeyforce commented 2 years ago

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"
quadrifolia commented 2 years ago

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

experimental: { esmExternals: false, }

kien-ngo commented 2 years ago

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

Tobeyforce commented 2 years ago

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

experimental: { esmExternals: false, }

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

bruceharrison1984 commented 1 year ago

+1 on what exactly this fix is doing

Tobeyforce commented 1 year ago

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.