Skip to content
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

TypeError: Cannot read properties of undefined (reading '$$') when using 0.42.0 or newer #896

Closed
Trystan-SA opened this issue Nov 8, 2021 · 6 comments · May be fixed by #991
Closed

TypeError: Cannot read properties of undefined (reading '$$') when using 0.42.0 or newer #896

Trystan-SA opened this issue Nov 8, 2021 · 6 comments · May be fixed by #991
Assignees
Labels
bug Something isn't working

Comments

@Trystan-SA
Copy link

When I'm using any components from carbon-components-svelte. It trigger the following error :

chrome_bxTO9mFTBa
chrome_YRSjjmqjap

Here is the code that trigger the error. It happen when I'm using any components (buttons, forms, accordions):
Code_R6CQCZ0gOO

I don't have this issue if I'm using the 0.41.0 version. It start breaking at 0.42.0 or newer.

My package versions :
svelte: 3.44.1
esbuild: 0.13.12
esbuild-svelte: 0.5.7 (and tested with 0.5.3 too)

@ulvido
Copy link

ulvido commented Nov 16, 2021

same environment and same error for me too.
in my case, I send a component with a javascripts general Custom Event and catch the event at another place.

The error occurs if you want to render a received component with svelte:component

EXAMPLE CODE

create a custom event and dispatch at some far place
...

const register = new CustomEvent(
  "REGISTER_APP",
  {
    bubbles: true,
    detail: {
      mycomponent: SomeSvelteComponent,
    },
  }
)

window.dispatchEvent(register);
catch the custom event at store
...

export const customComponent = writable(undefined)

window.addEventListener("REGISTER_APP", e => {
  customComponent.set(e.detail.mycomponent)
});

...
use component
...

import { customComponent } from "./store"

<div>
  {#if $customComponent}
     <svelte:component this={$customComponent} />
  {/if}
</div>

...

image

something fails when setting the component but what that I dont know yet.
image

@onelesd
Copy link

onelesd commented Jan 10, 2022

Can confirm the same error with v0.42.0 or higher. My env:

svelte: 3.44.1
esbuild: 0.14.8
esbuild-svelte: 0.6.0

@metonym metonym added the bug Something isn't working label Jan 10, 2022
@metonym
Copy link
Collaborator

metonym commented Jan 10, 2022

I recall experiencing a similar error when using a Svelte library that ships bundled ESM code in addition to uncompiled Svelte source files.

Just a hunch, but I wonder if it is trying to use the bundled Carbon Svelte library instead of the uncompiled source.

@metonym metonym self-assigned this Jan 10, 2022
@onelesd
Copy link

onelesd commented Jan 10, 2022

Related issue: sveltejs/svelte#6584

@metonym
Copy link
Collaborator

metonym commented Jan 10, 2022

I was able to repro the error using esbuild + esbuild-svelte + carbon-components-svelte.

I definitely think it's related to esbuild using the compiled source code. When I manually changed the "main" field to point to the uncompiled Svelte source code, it worked.

- "main": "./lib/index.js",
- "module": "./lib/index.mjs",
+ "main": "./src/index.js",

It should be prudent to drop support for the bundled source code, and instead point the "svelte" and "main" fields to the Svelte source code. This practice also seems to be encouraged by svelte-kit package.

@Trystan-SA
Copy link
Author

Your PR fixed my issue. Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants