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

Can't export createWidget in Vite 5 #667

Closed
skinofstars opened this issue Oct 3, 2024 · 5 comments
Closed

Can't export createWidget in Vite 5 #667

skinofstars opened this issue Oct 3, 2024 · 5 comments
Labels
question Further information is requested

Comments

@skinofstars
Copy link

Hi, I've got a Sveltekit 2 project using Vite 5.

When I use import { createWidget } from '@typeform/embed'; I can't build as I get the following error:

"createWidget" is not exported by "node_modules/@typeform/embed/build/index.js"

This has worked when I was using Sveltekit 1, Vite 4.

@github-actions github-actions bot added the new Flag for new issues before someone replies label Oct 3, 2024
@mathio
Copy link
Contributor

mathio commented Oct 3, 2024

I am sorry but I have no experience using Sveltekit and limited experience using Vite. Can you please provide a reproducible example for both cases - eg. a repo(s) we can clone?

The build/index.js actually does export the createWidget function (it exports t object with t.createWidget function defined).

@mathio mathio added question Further information is requested and removed new Flag for new issues before someone replies labels Oct 3, 2024
@skinofstars
Copy link
Author

skinofstars commented Oct 4, 2024

Hi, example repo is here

https://github.com/WhoTargetsMe/typeform-sveltekit-example

Previously I was only getting the error on build, but with this example the error is in both build and dev.

image

Here is pretty much the entire code. You can find that in src/routes/+page.svelte

<script lang="ts">
  import "@typeform/embed/build/css/widget.css";
  import { createWidget } from "@typeform/embed";
  import { onMount } from "svelte";

  const formId = "y1uAAugn";

  let elem: HTMLElement;

  onMount(() => {
    elem = document.createElement("div");

    try {
      createWidget(formId, {
        container: elem,
      });
    } catch (error) {
      console.error("Error creating Typeform widget", error);
    }
  });
</script>

<div bind:this={elem} />

@mathio
Copy link
Contributor

mathio commented Nov 7, 2024

Hi @skinofstars

Are you still experiencing an issue with this?

I played around with your example. It looks like importing the embed lib like this works:

import * as pkg from '@typeform/embed';

My no experience with Svelte is limited, though. We did not test the lib with this framework.

Sorry for the delayed response.

@skinofstars
Copy link
Author

Hi, yes I did fix this!

My problem was document.createElement("div"). Once I bound to the element directly it worked. This is a working Typeform component in Svelte:

<script lang="ts">
	import '@typeform/embed/build/css/widget.css';
	import { createWidget } from '@typeform/embed';
	import { onMount } from 'svelte';

	export let formId: string;
	export let options = {};

	let elem: HTMLElement;

	onMount(() => {
		try {
			createWidget(formId, {
				container: elem,
				...options
			});
		} catch (error) {
			console.error('Error creating Typeform widget', error);
		}
	});
</script>

<div bind:this={elem} />

@mathio
Copy link
Contributor

mathio commented Nov 7, 2024

Thats great to hear 🚀 Thanks for sharing!

@mathio mathio closed this as completed Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants