question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`import` issues on Netlify, SvelteKit and ViteJS

See original GitHub issue

I’m getting the following error when building on Netlify:

7:22:56 PM: > Named export 'createWidget' not found. The requested module '@typeform/embed' is a CommonJS module, which may not support all module.exports as named exports.
7:22:56 PM: CommonJS modules can always be imported via the default export, for example using:
7:22:56 PM: import pkg from '@typeform/embed';
7:22:56 PM: const { createWidget } = pkg;

This traces back to:

import { createPopup } from '@typeform/embed';
let showRegistration: boolean = false;
function openRegistrationForm() {
	showRegistration = true;
	// ID omitted from code example
	createPopup('<id>', {
		container: document.querySelector('#register')
	});
}

The code above works fine in the dev environment but isn’t accepted by Netlify. I haven’t seen it on any other libraries. Unfortunately the solution in the error message doesn’t work locally (although it works in Netlify).

It’s not a permalink, but you can currently see the code context at this branch: https://github.com/bahaistudies/conference/tree/netlify-identity

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
benmccanncommented, Aug 23, 2022

This library appears to me to be using UMD: https://github.com/Typeform/embed/blob/bc9ddcb1c515617053c9d07480037cfa4a53f714/packages/embed/webpack.config.js#L50

Rather than use UMD and try to serve both browser and server with a single build, the nicer thing to do is typically to output a CJS build specified in main and an ESM build specified in module in package.json. Or better yet, just provide an ESM build in main and set type: "module". You can still provide a UMD build if you have users who include the library via a script tag, but it’s generally not preferred for npm packages

1reaction
mathiocommented, Jul 7, 2021

Hello @benaltair

I think this might be an issue with SvelteKit, please see the discussion here: https://github.com/sveltejs/kit/issues/928

Also related: https://github.com/vitejs/vite/issues/3024

Read more comments on GitHub >

github_iconTop Results From Across the Web

SvelteKit site builds locally, fails with Netlify, rollup import issue
Site: iil.is / iil-is.netlify.app In one of my pages I am importing a BibTeX / .bib file which starts with @inproceedings{...: import pubs...
Read more >
When deploying Sveltekit app to Netlify, build breaks with ...
This answer might differ based on which version of SvelteKit you have. Try to add the following to svelte.config.js : import preprocess from ......
Read more >
Adapters • Docs • SvelteKit
import adapter from '@sveltejs/adapter-auto'; import adapter from '@sveltejs/adapter-node';. With this, vite build will generate a self-contained Node app ...
Read more >
SvelteKit onMount async import weird behaviour on build with ...
I load a quill editor in onMount() and set the plugins and the initial value, it works perfectly in dev. But when I...
Read more >
Deploying a Static Site - Vite
Install the Netlify CLI $ npm install -g netlify-cli # Create a new site in ... After your project has been imported and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found