Dayjs building error on run build ?
Hi everyone,
I'm running into a build error in my Nuxt 3 app when executing pnpm run build, and I'm wondering if anyone else has experienced this.
It seems that Vite (via Rollup) fails to resolve the dayjs/plugin/updateLocale module, even though the plugin is supposed to be included automatically by dayjs-nuxt. Everything works fine during development, but the build fails in CI with this error coming from .nuxt/dayjs.imports.mjs.
This feels like a misconfiguration or maybe something that needs to be externalized explicitly β but according to the docs, updateLocale should be handled for us.
Has anyone encountered the same issue? Any insight would be appreciated before I dig further or apply a workaround directly in the config.
Thanks!
3 Replies
Hi @Dragofafmir. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the knowledge sources, this appears to be related to a known issue in Nuxt 3.16.x where the
preserveModules
option in Rollup is causing problems with certain modules, including dayjs plugins.
The error you're experiencing with dayjs is similar to issues reported in Nuxt 3.16.0 and 3.16.2, where imports like dayjs(...).isBetween is not a function
were failing during build time, even though they worked fine in development.
According to a Nuxt team member's response in a GitHub issue, this is caused by the preserveModules
option that was enabled in Nuxt v3.16.0. The recommended workaround is to add the following configuration to your nuxt.config.ts
file:
This configuration disables the preserveModules
option for the server build, which should resolve the issue with dayjs plugins not being properly resolved during the build process.
GitHub Issue: Nuxt 3.16.0 build and run preview error contains multiple confirmations that this workaround resolves similar issues with module resolution during build.
If you're using pnpm, you might also want to check if there are any hoisting issues that could be affecting module resolution, as some users reported similar problems with pnpm and Nuxt 3.16.x.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@205360140105285643> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
I was really hoping this would fix the problem, but... nope. The build issue persists
OK I don't know if the Docker image I was using recently changed something, but the root cause of the error was the absence of the --shamefully-hoist flag during pnpm install π