I’m encountering the error “ERR_REQUIRE_ESM: require() of ES Module …” whenever I install a new package or update an @types version. The specific module causing the issue seems to be Error [ERR_REQUIRE_ESM]
even when delete svgdom i get the same error in other package .
C:UsersPCDocumentsGiftyshopback_giftyshopnode_modulests-nodedistindex.js:851
return old(m, filename);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module C:UsersPCDocumentsGiftyshopback_giftyshopnode_modulessvgdommain-module.js from C:UsersPCDocumentsGiftyshopback_giftyshopsrccontrollersdashboardshop.ts not supported.
Instead change the require of main-module.js in C:UsersPCDocumentsGiftyshopback_giftyshopsrccontrollersdashboardshop.ts to a dynamic import() which is available in all CommonJS modules.
at require.extensions.<computed> [as .js] (C:UsersPCDocumentsGiftyshopback_giftyshopnode_modulests-nodedistindex.js:851:20)
at Object.<anonymous> (C:UsersPCDocumentsGiftyshopback_giftyshopsrccontrollersdashboardshop.ts:19:18)
at m._compile (C:UsersPCDocumentsGiftyshopback_giftyshopnode_modulests-nodedistindex.js:857:29) {
code: 'ERR_REQUIRE_ESM'
}
I make search and i try to chenge tsconfig i change the module from form comonjs
to esnext
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["src"]
}
but when i change the module i get new error :
Debugger attached.
TypeError: Unknown file extension ".ts" for C:UsersPCDocumentsGiftyshopback_giftyshopsrcmain.ts
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
at defaultLoad (node:internal/modules/esm/load:143:22)
at async ModuleLoader.load (node:internal/modules/esm/loader:403:7)
at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:285:45)
at async link (node:internal/modules/esm/module_job:78:21) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
i seem to be not logic for me cause i tryed all the solutions in internet but i steal butween those two error .
so if there is any solution or something that i did wrong please help me to find it out .