Nux3 3.0.0-rc.2 met Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
See original GitHub issueEnvironment
my package json
{ “private”: true, “scripts”: { “dev”: “nuxt dev”, “build”: “nuxt build”, “start”: “node .output/server/index.mjs”, “generate”: “nuxt generate”, “preview”: “nuxt preview”, “lint”: “eslint --ext ".ts,.js,.vue" --ignore-path .gitignore .”, “lintfix”: “eslint --fix --ext ".ts,.js,.vue" --ignore-path .gitignore .” }, “type”: “module”, “dependencies”: { “less”: “^4.1.2”, “primeicons”: “^5.0.0”, “primevue”: “^3.12.6”, “sass”: “^1.51.0”, “vue”: “^3.2.33” }, “devDependencies”: { “@nuxtjs/eslint-config-typescript”: “^10.0.0”, “@nuxtjs/eslint-module”: “^3.1.0”, “eslint”: “^8.15.0”, “eslint-config-prettier”: “^8.5.0”, “eslint-plugin-nuxt”: “^3.2.0”, “eslint-plugin-prettier”: “^4.0.0”, “nuxt”: “^3.0.0-rc.2”, “prettier”: “^2.6.2”, “mitt”: “^3.0.0”, “music-score-transition”: “^0.0.5”, “tone”: “^14.7.77”, “typescript”: “^4.6.4” } }
Reproduction
my nuxt-config.js import { defineNuxtConfig } from ‘nuxt’
// https://v3.nuxtjs.org/api/configuration/nuxt.config export default defineNuxtConfig({ build: { transpile: [‘primevue’,‘tone’], }, buildModules: [‘@nuxtjs/eslint-module’] })
i used at page.vue: import * as Tone from ‘tone’
Describe the bug
The error happend while use nuxt3+tone code import * as Tone from ‘tone’ it works fine on vue3 vite only occured with nuxt3
Additional context
No response
Logs
✔ Vite server built in 5190ms 23:59:52
✔ Vite server built in 3026ms 00:00:05
✔ Vite server built in 2279ms 00:00:08
(node:10045) 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)
✔ Vite server built in 3525ms
Issue Analytics
- State:
- Created a year ago
- Comments:9 (2 by maintainers)
Top GitHub Comments
Dear @wohui I’ve answered your question at https://github.com/Tonejs/Tone.js/issues/1081#issuecomment-1124751788. It is not related to
node-fetch
but another dependency that is not ESM compatible and needs transpilation.Starting with
nitropack@0.4.4
andunenv@0.5.2
we are using a cross-version compatible ofnode-fetch
(unjs/node-fetch-native) that should resolve this issue when multiple versions ofnode-fetch
exist in a project (v2 and v3 by different dependencies).Please use
npx nuxi upgrade --force
to receive the fix.If still having problems, please share your environment and also double check installed version of nitro from
node_moudles/nitropack/package.json
.For the context, there is still another underlying issue that caused v2 and v3 of node-fetch being merged and therefore this error (https://github.com/unjs/nitro/issues/161) we are tracking it but should not be relevant anymore at least regarding
node-fetch
.Cheers!