N
Nuxtβ€’7d ago
Dragofafmir

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!
[nuxi] ERROR Nuxt Build Error: [vite]: Rollup failed to resolve import "dayjs/plugin/updateLocale" from "/src/node_modules/.cache/nuxt/.nuxt/dayjs.imports.mjs".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
build.rollupOptions.external
[nuxi] ERROR Nuxt Build Error: [vite]: Rollup failed to resolve import "dayjs/plugin/updateLocale" from "/src/node_modules/.cache/nuxt/.nuxt/dayjs.imports.mjs".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
build.rollupOptions.external
3 Replies
kapa.ai
kapa.aiβ€’7d ago
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:
export default defineNuxtConfig({
vite: {
$server: {
build: {
rollupOptions: {
output: {
preserveModules: false
}
}
}
}
}
})
export default defineNuxtConfig({
vite: {
$server: {
build: {
rollupOptions: {
output: {
preserveModules: false
}
}
}
}
}
})
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: ----------------------
kapa.ai
kapa.aiβ€’7d ago
<@205360140105285643> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Dragofafmir
DragofafmirOPβ€’7d ago
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 πŸ’€

Did you find this page helpful?