preact icon indicating copy to clipboard operation
preact copied to clipboard

app.js:16 Uncaught TypeError: Cannot read properties of undefined (reading '__H')

Open gideonmkp98 opened this issue 1 year ago • 10 comments

I've got a problem when building Preact with gulp.

After building the project my console gives me this error: "app.js:16 Uncaught TypeError: Cannot read properties of undefined (reading '__H')"

image

And this is the code where import the useState

` import { useState } from 'preact/compat';

const [count, setCount] = useState(0);

const increment = () => setCount(count + 1);

export default () => (

<button onClick={increment}>{count}
); `

and this is the function in my gulpfile.js:

image

does someone know how i can fix this problem? or are there any recommendations as alternative for gulp?

gideonmkp98 avatar Aug 09 '22 16:08 gideonmkp98

You are using different aliases 😅 your alias goes to preact-compat which probably means that you are working with conflicting versions of preact

JoviDeCroock avatar Aug 09 '22 16:08 JoviDeCroock

You are using different aliases 😅 your alias goes to preact-compat which probably means that you are working with conflicting versions of preact

What alias do i have to use to get it working ?

gideonmkp98 avatar Aug 09 '22 16:08 gideonmkp98

The same one as your code there preact/compat, preact-compat is used with v8. You can read about the aliases in our docs

JoviDeCroock avatar Aug 09 '22 16:08 JoviDeCroock

The same one as your code there preact/compat, preact-compat is used with v8. You can read about the aliases in our docs

Still the same error as before after changing it :(

image

gideonmkp98 avatar Aug 09 '22 16:08 gideonmkp98

I mean, let's maybe first get our details sorted. Did this work before, or what did you have before? Is this a fresh project, ...?

Generally this error happens when your bundler is generating duplicate versions of libraries.

JoviDeCroock avatar Aug 09 '22 16:08 JoviDeCroock

Yeah it's a fresh project..

https://github.com/gideonmkp98/preact-test this is the link to my repo maybe you can see something that's weird about it

gideonmkp98 avatar Aug 09 '22 16:08 gideonmkp98

this error seems to occur on a few different bundlers. I checked my bundle on webpack and I can be wrong but it doesn't generate a duplicate version, maybe it resolve wrongly

nmocruz avatar Aug 11 '22 10:08 nmocruz

Got the same issue when updating preact from 10.0.0 to 10.0.6. I end up with two copies of preact in the node_modules, see output of npm explain below

npm explain preact     
[email protected]
node_modules/preact
  preact@"10.10.6" from the root project
  peer preact@"^10.0.0" from @prefresh/[email protected]

dmail avatar Sep 06 '22 09:09 dmail

This suggest @prefresh/[email protected] depends on preact "10.0.0" but I have opened the package.json and found the following:


  "peerDependencies": {
    "preact": "^10.0.0"
  }

I tried to reinstall from scratch with the following

rm -rf node_modules
rm package-lock.json
npm cache clean --force
npm install

The issue persists: I still have 2 versions of preact (10.0.0 and 10.0.6) in node modules My npm version is 8.5

dmail avatar Sep 06 '22 09:09 dmail

Found a fix for my situation: use an other browser. Which makes me realize it was due to browser cache so I reloaded the page with cache disabled in chrome devtools. Now the issue is gone.

dmail avatar Sep 06 '22 09:09 dmail