-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't import dayjs on dev server #699
Comments
If you figured it out, would you be able to post the solution here for others? |
Hey @benmccann ! I added the solution at the top of my original post before closing, but I'll post it here again for the "scrollers". 😄 Fixed by specifically importing the ES module directly Example: import dayjs from "dayjs/esm";
import relativeTime from "dayjs/esm/plugin/relativeTime"; |
@khromov I still get the error. I did not change anything else, just added the On
|
@NoelJacob This sounds like it might be a different issue. Make sure you are running the latest version of Node (v15) which has support for ES Modules, try using Since you're on Windows I can also suggest using Ubuntu or Debian on WSL2 instead of a native Window environment! |
getting the same error as @NoelJacob with latest Node (v16.3.0). Has anyone solved this in the meantime? |
You shouldn't have to do that, but dayjs is missing the These issues are caused by iamkun/dayjs#1314 |
|
same error here too.
Happens upon npm run build Strangely enough, when i change everything back and add the .js extension:
it works |
You can use the following flag to get the build to pass without adding NODE_OPTIONS='--experimental-specifier-resolution=node' svelte-kit build This will lead to errors in the production/preview build in some cases but is useful for debugging. |
Dayjs maintainer has created the v2.0 branch: iamkun/dayjs#1281 (comment) |
import dayjs from 'dayjs'
Ideas? |
Re-installed with Above message now disappears, but this shows up related to the dayjs import:
|
Please try dayjs 2.0, which has native support for ESM |
When upgrading note that as of |
Thanks! |
Thank you @vhscom , do you know of a working plug-in overview for v2? |
There are 2 of 30+ plugins already ported in the |
Just to sum this up (19.08.2022): <script context="module">
import dayjs from 'dayjs';
import isoWeek from 'dayjs/plugin/isoWeek'
dayjs.extend(isoWeek);
const isoWeekNumber = dayjs().isoWeek();
</script>
<div>{isoWeekNumber}</div> |
Edit: Fixed by specifically importing the the ES module
Original bug report
Describe the bug
We have a basic component that imports
dayjs
, but there is an error displaying a page with this component when usingnpm run dev
. Running in production withnpm run build && npm start
works fine.The component:
Logs
Browser logs
To Reproduce
✅ Please make sure you've tested with the latest versions of Svelte and SvelteKit.
Information about your SvelteKit Installation:
npx envinfo --system --npmPackages svelte,@sveltejs/kit --binaries --browsers
Your browser
Chrome 89
Your adapter (e.g. Node, static, Vercel, Begin, etc...)
Node
Severity
Blocking SvelteKit usage.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: