Nuxt chunking error when build (v4.1.1)

I got build error after upgrade to nuxt 4.1.1
Nuxt Build Error: [nuxt:tree-shake-composables:transform] Cannot split a chunk that has already been edited
Nuxt Build Error: [nuxt:tree-shake-composables:transform] Cannot split a chunk that has already been edited
After debugging, i found that the affected parts are normally arrow functions (either async or not) passed into onMounted Like
onMounted(() => {
// Do something
})
onMounted(() => {
// Do something
})
And i had to fix it with
function doSomething() {}
onMounted(doSomething)
function doSomething() {}
onMounted(doSomething)
Then the build works again! I think this might be a bug, it could be something inside the arrow function caused the issue or the arrow function itself affected the new build chunking feature
3 Replies
kapa.ai
kapa.ai3mo ago
Hi @TaQuanMinhLong. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I'm sorry, but the knowledge sources provided do not contain explicit information about the specific Nuxt build error:
[nuxt:tree-shake-composables:transform] Cannot split a chunk that has already been edited
[nuxt:tree-shake-composables:transform] Cannot split a chunk that has already been edited
nor do they mention issues with using arrow functions in onMounted handlers in Nuxt 4.1.1 or the new tree-shaking/chunking features causing this error. There are several documents discussing chunking, tree-shaking, and related build optimizations in Nuxt, such as improvements to tree-shaking of composables and chunk stability, but none directly address this error or the workaround you described with arrow functions and onMounted handlers. Therefore, I cannot confirm whether this is a known bug or provide an official workaround based on the current knowledge sources. If you believe this is a bug, I recommend opening an issue on the Nuxt GitHub repository with a minimal reproduction, as this will help the Nuxt team investigate and address the problem. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@595420339551338507> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
TaQuanMinhLong
TaQuanMinhLongOP3mo ago
GitHub
Nuxt 4.1.1: Nuxt Build Error: [nuxt:tree-shake-composables:transfor...
I got build error after upgrade to nuxt 4.1.1 Nuxt Build Error: [nuxt:tree-shake-composables:transform] Cannot split a chunk that has already been edited After debugging, i found that the affected ...

Did you find this page helpful?