preact
preact copied to clipboard
app.js:16 Uncaught TypeError: Cannot read properties of undefined (reading '__H')
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')"
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 () => (
and this is the function in my gulpfile.js:
does someone know how i can fix this problem? or are there any recommendations as alternative for gulp?
You are using different aliases 😅 your alias goes to preact-compat
which probably means that you are working with conflicting versions of preact
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 ?
The same one as your code there preact/compat
, preact-compat
is used with v8. You can read about the aliases in our docs
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 :(
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.
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
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
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]
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
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.