question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

Environment

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:closed
  • Created a year ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
pi0commented, May 12, 2022

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.

1reaction
pi0commented, May 11, 2022

Starting with nitropack@0.4.4 and unenv@0.5.2 we are using a cross-version compatible of node-fetch (unjs/node-fetch-native) that should resolve this issue when multiple versions of node-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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

"module" in the package.json or use the .mjs extension - Stack ...
So I set "type":"module" on package.json and press f5 again. and another error show up. Process exited with code 1 Uncaught ...
Read more >
"module" in the package.json or use the .mjs extension 2022
The warning To load an ES module, set “type”: “module” in the package.json or use the .mjs extension occurs when using ES6 Module...
Read more >
ES Modules · Nuxt Concepts
(node:22145) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension./path/to/index.js:1export default ...
Read more >
Packages | Node.js v18 API
A package.json "type" value of "module" tells Node.js to interpret .js files ... Files ending with .mjs are always loaded as ES modules...
Read more >
https://nodejs.org/api/esm.md
Authors can tell Node.js to use the ECMAScript modules loader via the `.mjs` file extension, the `package.json` [`"type"`][] field, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found