Nuxt 4 - compability version (node:81791) Warning: To load an ES module, set "type": "module" in...

{
"name": "studio",
"type": "module",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"lint": "eslint . --ext .vue,.js,.ts",
"lint:fix": "eslint . --fix --ext .vue,.js,.ts"
},
{
"name": "studio",
"type": "module",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"lint": "eslint . --ext .vue,.js,.ts",
"lint:fix": "eslint . --fix --ext .vue,.js,.ts"
},
Hello everyone, I'm encountering an issue while building a Nuxt 3.14.159 project using Bun. The build process fails with the following error:
[10:37:04 AM] ERROR (node:81791) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use node --trace-warnings ... to show where the warning was created)

[10:37:04 AM] ERROR (node:81791) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
[10:37:04 AM] ERROR (node:81791) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use node --trace-warnings ... to show where the warning was created)

[10:37:04 AM] ERROR (node:81791) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
The package.json includes "type": "module". The nuxt.config.ts specifies compatibilityVersion: 4 and compatibilityDate: '2024-04-03'.
5 Replies
kapa.ai
kapa.ai2mo ago
Hi @Hermes Alves. 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 information provided in your question and the knowledge sources available, it seems you're encountering an issue related to ES modules while using Nuxt with Bun. Let's address this step by step: 1. First, it's important to note that you're using Nuxt 3.14.159 with compatibilityVersion: 4 set in your nuxt.config.ts. This means you're opting in to Nuxt 4 behavior, as described in the Nuxt Upgrade Guide (https://nuxt.com/docs/getting-started/upgrade#opting-in-to-nuxt-4). 2. You've correctly set "type": "module" in your package.json, which is a step in the right direction for ES module support. 3. The error message you're seeing is typically related to Node.js trying to load ES modules. However, you mentioned you're using Bun, not Node.js directly. 4. Nuxt's documentation and configuration are primarily focused on Node.js environments, and there might be some compatibility issues when using Bun as the runtime. Given this context, here are some suggestions: 1. Ensure that you're using the latest version of Bun, as ES module support might have improved in recent releases. 2. Try running your Nuxt project with Node.js instead of Bun to see if the issue persists. If it works with Node.js, it might indicate a compatibility issue with Bun. 3. Check if all your project files that are intended to be ES modules use the .mjs extension, as suggested in the ES Modules documentation (https://nuxt.com/docs/guide/concepts/esm#library-author-guide). 4. If you're using any third-party libraries, make sure they are compatible with ES modules and Nuxt 4's behavior. 5. You might want to try removing the compatibilityVersion: 4 setting temporarily to see if the issue is related to the new Nuxt 4 behaviors. If these steps don't resolve the issue, you may want to: - Check the Bun documentation for any specific instructions on using it with Nuxt or ES modules. - Report this as a potential issue to the Nuxt community, as it might be a compatibility problem between Nuxt 4 features and Bun. Remember, Nuxt 4 is still in development, and using compatibilityVersion: 4 might introduce some instability or compatibility issues, especially with non-standard runtimes like Bun. Nuxt ES Modules Troubleshooting (https://nuxt.com/docs/guide/concepts/esm#troubleshooting-esm-issues) might provide additional insights, although it's more focused on library-related issues rather than runtime problems. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@727670710033580124> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Hermes Alves
Hermes AlvesOP2mo ago
@kapa.ai I'm encountering a persistent warning while running my Nuxt 3.14.159 application using both Bun and npm as package managers. The warning appears as follows: (node:84434) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
Nuxt Version: 3.14.159
Nitro Version: 2.10.4
Compatibility Version: 4 (set via compatibilityDate: '2024-04-03' and future: { compatibilityVersion: 4 })
Package Managers Tested: Bun and npm
Node.js Version: v22.2.0
Nuxt Version: 3.14.159
Nitro Version: 2.10.4
Compatibility Version: 4 (set via compatibilityDate: '2024-04-03' and future: { compatibilityVersion: 4 })
Package Managers Tested: Bun and npm
Node.js Version: v22.2.0
The warning appears during both development (npm run dev and bun run dev) and build processes. The application runs, but I’m concerned that this warning may indicate an underlying issue that could affect future updates or production stability. 1. Is this warning indicative of a deeper problem that should be addressed? 2. Are there specific configurations or steps I might be overlooking to resolve this? 3. Could the compatibility version setting be related, and if so, is there a way to address it without the warning?
Merite
Merite2mo ago
you neeed to mention kapa.ai with @ to get an answer
Hermes Alves
Hermes AlvesOP2mo ago
@kapa.ai I'm encountering a persistent warning while running my Nuxt 3.14.159 application using both Bun and npm as package managers. The warning appears as follows: (node:84434) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
Nuxt Version: 3.14.159
Nitro Version: 2.10.4
Compatibility Version: 4 (set via compatibilityDate: '2024-04-03' and future: { compatibilityVersion: 4 })
Package Managers Tested: Bun and npm
Node.js Version: v22.2.0
Nuxt Version: 3.14.159
Nitro Version: 2.10.4
Compatibility Version: 4 (set via compatibilityDate: '2024-04-03' and future: { compatibilityVersion: 4 })
Package Managers Tested: Bun and npm
Node.js Version: v22.2.0
The warning appears during both development (npm run dev and bun run dev) and build processes. The application runs, but I’m concerned that this warning may indicate an underlying issue that could affect future updates or production stability. 1. Is this warning indicative of a deeper problem that should be addressed? 2. Are there specific configurations or steps I might be overlooking to resolve this? 3. Could the compatibility version setting be related, and if so, is there a way to address it without the warning?
Want results from more Discord servers?
Add your server