Skip to content

Commit 6521c22

Browse files
committed
Fix importing as ESM by using conditional exports
This fixes the following issue when exporting the site as a static bundle using SvelteKit. ``` > Using @sveltejs/adapter-static > Named export 'SvelteToast' not found. The requested module '@zerodevx/svelte-toast' is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default export, for example using: import pkg from '@zerodevx/svelte-toast'; const {SvelteToast} = pkg; ```
1 parent a9fb267 commit 6521c22

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"svelte": "src/index.js",
77
"module": "dist/index.mjs",
88
"main": "dist/index.js",
9+
"exports": {
10+
"require": "./dist/index.js",
11+
"import": "./dist/index.mjs"
12+
},
913
"scripts": {
1014
"tailwind:watch": "chokidar 'docs/tailwind*.*' -c 'npm run tailwind:build'",
1115
"tailwind:build": "tailwind build docs/tailwind.css -c docs/tailwind.config.js -o docs/build/global.css",

src/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
import SvelteToast from './SvelteToast.svelte'
2-
import { toast } from './stores'
3-
4-
export { SvelteToast, toast }
1+
export { default as SvelteToast } from './SvelteToast.svelte'
2+
export { toast } from './stores'

0 commit comments

Comments
 (0)