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" } }
This means the library you're trying to require cannot be imported using the require syntax.
I think the version of the nanoid you're using needs to be imported using import
You could try downgrading nanoid or switching to the import keyword.