You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How do I create a default export in a svelte-kit package? Would be cool if the docs included some guidance on that. If I add an index file that re-exports a Svelte component as default,
Must use import to load ES Module: my-package/index.js
require() of ES modules is not supported.
require() of my-package/index.js from repo/node_modules/vite/dist/node/chunks/dep-0ed4fbc0.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from my-package/package.json.
The easiest solution to this in the past was to use the "svelte" field in package.json but sveltekit package does not copy that field into its output.
There's nothing wrong with your export code, it's still a vite problem that can't properly handle it, #1148 patches it by forcing packages with "svelte" to be bundled in ssr.noExternal. Since library published with svelte-kit package have a predefined package keys, there's no other way to fix it (currently) other than manually adding "svelte": "index.js" after packaging, or your library name to ssr.noExternal in the svelte config file.
#1735 would solve this as it will preserve the original package.json as is, so you can write "svelte" key yourself and point it to any file you want.
How do I create a
default
export in asvelte-kit package
? Would be cool if the docs included some guidance on that. If I add an index file that re-exports a Svelte component asdefault
,and then install the package and try
I get
The easiest solution to this in the past was to use the
"svelte"
field inpackage.json
butsveltekit package
does not copy that field into its output.I asked this question here as well.
The text was updated successfully, but these errors were encountered: