N00nDay / stwui

Opinionated yet customizable Svelte-TailwindCSS component library
stwui.vercel.app
MIT License
447 stars 21 forks source link

dayjs error when importing directly from 'stwui' #210

Closed codepilotsf closed 8 months ago

codepilotsf commented 8 months ago

Current Behavior

In a fresh SvelteKit 2.0 application, if I install stwui, then try to import any component like this: import { Alert } from 'stwui';

I hit this error:

SyntaxError: [vite] Named export 'Dayjs' not found. The requested module 'dayjs' 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 'dayjs';
const {Dayjs} = pkg;

    at analyzeImportedModDifference (file:///Users/sean/Repositories/launchpad/node_modules/.pnpm/vite@5.0.11/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:50953:19)
    at nodeImport (file:///Users/sean/Repositories/launchpad/node_modules/.pnpm/vite@5.0.11/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:50904:9)
    at async ssrImport (file:///Users/sean/Repositories/launchpad/node_modules/.pnpm/vite@5.0.11/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:50799:24)
    at async eval (/Users/sean/Repositories/launchpad/node_modules/.pnpm/stwui@0.21.0-next_@sveltejs+kit@2.3.0_svelte@4.2.8/node_modules/stwui/components/datepicker/date-utils.js:3:44)
    at async instantiateModule (file:///Users/sean/Repositories/launchpad/node_modules/.pnpm/vite@5.0.11/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:50861:9)

The workaround is is to use this syntax: import Alert from 'stwui/alert';

Expected Behavior

No error.

Steps To Reproduce

  1. npm create svelte@latest test
  2. cd test
  3. npm install; npm install stwui --legacy-peer-deps
  4. Edit routes/+page.js adding the script block with import to top of file:
    <script>
    import { Alert } from 'stwui';
    </script>

Link to Reproduction / Stackblitz

No response

More Information

No response

N00nDay commented 8 months ago

There is something else at play here. I just tested this and everything is working as expected with no errors. Please create a basic reproduction of this. Until then, I am not sure which tail to chase because I am not seeing one on my end.

N00nDay commented 8 months ago

After addressing your issue I see now why you are getting this error. Both issues will be resolved in the next update.