Skip to content

bind:this not working in exported component #2620

@ValentinH

Description

@ValentinH

I've created my first Svelte 3 component 🎉 and I'd like to share it. Unfortunately, I'm encountering an issue when importing it using the generated index.js file: DOM element binding using the bind:this attribute doesn't work apparently (or the way my component is exported is wrong maybe).

If I import my component in a Svelte application, it works fine because it reads the pkg.svelte file.

However, in another environment which doesn't read the svelte property, like CodeSandbox, it breaks. Basically, when onMount is called, the element is not bound and I get Cannot read property 'addEventListener' of null when trying to add a listener on it.

Demo of the issue: https://codesandbox.io/s/o443j977j5
My component source: https://github.com/ValentinH/svelte-easy-crop/blob/master/src/Cropper.svelte

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions