how to fix it , I'm doing App chat . Sorry if the language is difficult to read, I'm Thai.
PS C:\Users\ADMIN\Desktop\chat\server> node server.js
C:\Users\ADMIN\Desktop\chat\server\server.js:4
const { nanoid } = require("nanoid");
^
[ERR_REQUIRE_ESM]: require() of ES Module
C:\Users\ADMIN\Desktop\chat\server\node_modules\nanoid\index.js from
at Object.<anonymous> (C:\Users\ADMIN\Desktop\chat\server\server.js:4:20) {
code: 'ERR_REQUIRE_ESM'
{
"name": "chat",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"keywords": [], "author": "", "license": "ISC", "dependencies": { "express": "^4.18.1", "nanoid": "^4.0.0", "socket.io": "^4.5.1" } }
The problem is that you are using nanoid Ver.4.0.0 . It seems that a new feature in V.4 (support for ESM) is a braking change.
The full documentation is in this link to issue#365 in the nanoid GitHub repo.
The comment that helped me and I base my solution on was from @salyndev0
To fix the problem follow these steps:
Uninstall nanoid: npm uninstall nanoid
Install Version 3 supporting all 3.x.x: npm install nanoid@^3.0.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With