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.

SvelteKit - failing on import... any ideas?

See original GitHub issue
<script>
    import Carousel from "svelte-carousel";
</script>

Cannot use import statement outside a module
C:\...\app\node_modules\svelte-carousel\src\main.js:1
import Carousel from './components/Carousel/Carousel.svelte'

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:984:16)
    at Module._compile (internal/modules/cjs/loader.js:1032:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at nodeRequire (C:\...\app\node_modules\vite\dist\node\chunks\dep-e9a16784.js:68211:17)
    at ssrImport (C:\...\app\node_modules\vite\dist\node\chunks\dep-e9a16784.js:68164:20)
    at eval (/src/embed/calc/CalcMortgagePayment.svelte:7:31)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
vadimkorrcommented, May 30, 2021

When using with SvelteKit do the following:

The official workaround is:

  1. Install it as a dev dependency: npm install svelte-carousel -D

  2. Import it like this:

<script>
  import { onMount } from 'svelte';

  let Carousel;
  onMount(async () => {
    const module = await import('svelte-carousel');
    Carousel = module.default;
  });
</script>

<svelte:component this={Carousel}>
  <div>1</div>
  <div>2</div>
  <div>3</div>
</svelte:component>

How do I use a client-side only library that depends on document or window? why -D ?

2reactions
OClementcommented, Mar 18, 2022

FYI: This issue is back on 1.0.17-rc4 (latest as of this writing) Downgrading to 1.0.16 and using the workwaround above still works

Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors • Docs • SvelteKit
An expected error is one created with the error helper imported from ... An unexpected error is any other exception that occurs while...
Read more >
Svelte Kit failed to resolve import "svelte-persistent-store/ ...
It looks like the alternative usage works correctly in SvelteKit: // ❌ fails to resolve // import { writable, readable, derived } from ......
Read more >
Doing Advent of Code in SvelteKit. Is it possible to ...
I'm already maintaining this file with the titles of each problem, maybe there's a way to dynamically import and render all the DayXX ......
Read more >
Getting Started with SvelteKit: 10 Tips
Want to see what all the buzz is about? Read on to find out how to learn Svelte and also some key tips...
Read more >
Solved: Svelte Kit Build Error
js' is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default ......
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