RollupError related to Vue5.8.3(?)

Hi there! When I try to build my Nuxt 4 project I get an error that I can't figure out how to fix:
[3:16:24 PM] ERROR node_modules/.cache/nuxt/.nuxt/dist/server/server.mjs (1:7): "default" is not exported by "node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue/index.mjs", imported by "node_modules/.cache/nuxt/.nuxt/dist/server/server.mjs".
[3:16:24 PM] ERROR node_modules/.cache/nuxt/.nuxt/dist/server/server.mjs (1:7): "default" is not exported by "node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue/index.mjs", imported by "node_modules/.cache/nuxt/.nuxt/dist/server/server.mjs".
Possibly related is this warning:
[3:16:20 PM] WARN [plugin commonjs--resolver] It appears a plugin has implemented a "resolveId" hook that uses "this.resolve" without forwarding the third "options" parameter of "resolveId". This is problematic as it can lead to wrong module resolutions especially for the node-resolve plugin and in certain cases cause early exit errors for the commonjs plugin.
In rare cases, this warning can appear if the same file is both imported and required from the same mixed ES/CommonJS module, in which case it can be ignored.
[3:16:20 PM] WARN [plugin commonjs--resolver] It appears a plugin has implemented a "resolveId" hook that uses "this.resolve" without forwarding the third "options" parameter of "resolveId". This is problematic as it can lead to wrong module resolutions especially for the node-resolve plugin and in certain cases cause early exit errors for the commonjs plugin.
In rare cases, this warning can appear if the same file is both imported and required from the same mixed ES/CommonJS module, in which case it can be ignored.
2 Replies
kapa.ai
kapa.ai3mo ago
Hi @Sasja is back. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The error you're seeing:
"default" is not exported by "node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue/index.mjs", imported by "node_modules/.cache/nuxt/.nuxt/dist/server/server.mjs".
"default" is not exported by "node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue/index.mjs", imported by "node_modules/.cache/nuxt/.nuxt/dist/server/server.mjs".
is a classic ES module (ESM) and CommonJS interop issue. This happens when a module is being imported as a default export, but the actual file does not provide a default export in the way the bundler (Rollup, via Vite) expects. Why does this happen? - Some libraries, especially those that are "fake ESM" (written in ESM syntax but not fully compatible with Node ESM expectations), can cause this issue. - The warning about the "resolveId" hook is related to plugin internals and can sometimes be ignored, but it may also indicate a plugin is not handling module resolution correctly, which can contribute to these issues. How to fix or work around it: 1. Transpile the problematic library:
You can tell Nuxt to transpile the library, which sometimes resolves ESM/CJS issues. In your nuxt.config:
export default defineNuxtConfig({
build: {
transpile: ['vue']
}
})

export default defineNuxtConfig({
build: {
transpile: ['vue']
}
})

2. Manually alias the library:
If the above doesn't work, you can try aliasing the import to a different entry point (such as a CJS build), though for Vue this is rarely needed and not generally recommended. 3. Interop the default export:
If you are importing Vue somewhere manually, use:
import { default as Vue } from 'vue'

import { default as Vue } from 'vue'

Or, if using dynamic import:
import('vue').then(m => m.default || m)

import('vue').then(m => m.default || m)

However, in most Nuxt projects, you shouldn't need to import Vue directly. 4. Check for upstream issues:
This kind of error is often due to the way the upstream library (in this case, Vue) is published. If you're using a non-standard or pre-release version of Vue, try switching to a stable release. 5. General ESM troubleshooting:
The Nuxt docs provide more details and recommend using the mlly package for more complex interop situations, but for most users, the above steps should suffice. See the Nuxt ESM troubleshooting guide for more details. Summary:
This is a known issue with ESM/CJS interop in the Node ecosystem, especially when using bundlers like Rollup. Try transpiling the library or adjusting your imports as above. If the problem persists, check if you're using a non-standard version of Vue or if any plugins in your build process might be interfering with module resolution. For more details and examples, see the official Nuxt documentation on troubleshooting ESM issues. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@187454025925525504> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?