-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
🐛 BUG: Cannot read properties of undefined (reading '__H') in component library #3449
Comments
User reported issues: This looks like a small issue with dependencies within the |
Sorry, I had made a small mistake in my repro (not installing the component library dependencies) and that lead to the wrong issue showing up. I updated the ticket accordingly. |
Thanks for reporting @d3x7r0! From testing, it seems this is an issue with Vite bundling Preact, resulting in a duplicate Preact during development. This is the best fix right now: // astro.config.mjs
import { defineConfig } from 'astro/config';
import preact from "@astrojs/preact";
export default defineConfig({
integrations: [preact()],
// add a vite config to your astro.config.mjs
vite: {
ssr: {
// add your package to the `noExternal` list
noExternal: ['my-package']
}
}
}); ☝️ Let me know if |
I'm sad to say that it doesn't seem to solve it.
|
Ack, understood. We'll wait for the Vite 3 migration to finish before re-testing. Dependency management should improve once this is out! |
Hi All - I'm running into this as well. Is there any workaround with Vite 2? |
FYI: I was able to get this working in my project by adding
|
Vite 3 may have fixed this in the latest RC versions of Astro! @bholmesdev to confirm, and if not look into: |
i am stilly facing this error in latest RC ie 1.0.0-rc.3 @FredKSchott @bholmesdev |
Does anyone have an example that's not using a monorepo setup like in the initial post? |
I'm not sure the OP is actually a bug. There are 2 different But since there are multiple reports here I'm guessing they aren't all using this setup. |
@matthewp I modified the minimal repro to make |
Hi there. Just a minor clarification about my example: I'm hitting this issue exactly as the repo shows. I have two completely separate projects that depend on each other. They are not on the same repo, I just put them both in the same one to make the example easier. Presumably the same issue would happen on any other library that has preact as a peer dependency instead of react (those are pretty rare admittedly). EDIT: btw I updated the repo with the latest versions and removed any extra libraries. Also moved preact to "peerDeps" (since that's the more arguably "correct" way to describe the dependencies of the library part of the repro). That said, the new error message is even weirder to me:
|
@bholmesdev It doesn't matter if its a devDependency or regular, the same result is that you have 2 node_modules/ folders that do not have a common root, and therefore Node will load preact in each of those. Node does not dedupe based on semver or anything like that, it simply walks up node_modules/ folders until it finds a copy. |
@matthewp sorry but I think my example is muddying the waters here a bit. I used a separate folder and used an npm file dependency to simplify but this happens when you have a dependency that's of the type module and which depends on preact. What happens is that vite, somehow, doesn't dedupe the This is the end result of installing such a dependency:
Notice how there's only a single preact in the tree and the error still shows up. |
@d3x7r0 can you fork this and make it break? https://stackblitz.com/edit/github-exuehl?file=src/pages/index.astro It's unclear to me what's different about this example from what you are doing. |
Ah, ok I can get it to break by adding https://stackblitz.com/edit/github-exuehl?file=one%2Fmain.js |
@matthewp it does look that way. I can't even begin to venture a guess though. I don't know too much about Vite internals :-( |
Maybe it's related to this issue? vitejs/vite#8378 |
Ok so good news. By manually adding the So long as the library code is using plain JS and not JSX. Maybe this is something that could be added to |
The problem is that |
Still getting tnis issue with latest (v1.0.2) astrojs and then adding preact integration |
Hey folks, I found my way here from an issue on the Preact repo. I don't know if this is going to be helpful for the Preact Astro integration, but this solved it for me with Preact + Vitest: Here's a copy of my reply over there: I just ran into this issue with Preact + Vitest and found this solution on a similar issue on the Vitest repo: vitest-dev/vitest#1652 (comment). Forcing the aliased module to load using Stuck this at the top of my
Then I've got a
This is apparently due to the way Vite imports unprocessed modules. I don't really understand the CJS vs ESM madness and wish it wasn't a thing. Weirdly, I only had this problem with |
Astro v4.12.3 hello everyone I have the same problem with the current versions of preact and astro. I tried everything in this thread but absolutely nothing worked for me, has anyone had the same thing happen to them with recent versions? |
Hey @illiantech! Been there, it’s not a fun issue to debug. Would you mind trying to reproduce in a Stackblitz example? If you can reproduce, I suggest opening a new GitHub issue. |
+1. Same issue with astro ssr |
What version of
astro
are you using?1.0.0-beta.34
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm
What operating system are you using?
Mac
Describe the Bug
Attempting to use a separate npm package with components written in preact leads to an error where preact components cannot be renderered.
Link to Minimal Reproducible Example
https://github.com/d3x7r0/astro-test
Participation
The text was updated successfully, but these errors were encountered: