getjerry / nest-casl

Casl integration for NestJS
MIT License
225 stars 29 forks source link

Error [ERR_REQUIRE_ESM]: require() of ES Module #825

Closed AxelReid closed 9 months ago

AxelReid commented 9 months ago

When running i'm having this error:

/home/axelreid/MyFiles/Fullstack Projects/zap/backend/node_modules/nest-casl/dist/access.service.js:15
const flat_1 = require("flat");
               ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/axelreid/MyFiles/Fullstack Projects/zap/backend/node_modules/flat/index.js from /home/axelreid/MyFiles/Fullstack Projects/zap/backend/node_modules/nest-casl/dist/access.service.js not supported.
Instead change the require of index.js in /home/axelreid/MyFiles/Fullstack Projects/zap/backend/node_modules/nest-casl/dist/access.service.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/axelreid/MyFiles/Fullstack Projects/zap/backend/node_modules/nest-casl/dist/access.service.js:15:16)
    at Object.<anonymous> (/home/axelreid/MyFiles/Fullstack Projects/zap/backend/node_modules/nest-casl/dist/casl.module.js:13:26)
    at Object.<anonymous> (/home/axelreid/MyFiles/Fullstack Projects/zap/backend/node_modules/nest-casl/dist/index.js:4:21)
    at Object.<anonymous> (/home/axelreid/MyFiles/Fullstack Projects/zap/backend/dist/src/app.module.js:20:21)
    at Object.<anonymous> (/home/axelreid/MyFiles/Fullstack Projects/zap/backend/dist/src/main.js:8:22)

I tried the version of nest-casl from ^1.8.8 to ^1.9.1

Tried with the node versions v18.x and v20.x

Tried to change the nestjs related packages also

tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "esModuleInterop": true,
    "moduleResolution": "Node"
  }
}

Also tried to change around the config a little bit but i couldn't find a solution

I didn't have this problem just before, when i was putting project on a server i had to play around with the package.json but didn't change deps much, i mostly removed node_modules and package-lock.json and re-install many times

owenlejeune commented 9 months ago

Running into the same error

liquidautumn commented 9 months ago

This is due to recently added flat package is ESM only thus failing in CommonJS environment. Downgrading it in #827 to resolve this issue.

liquidautumn commented 9 months ago

Resolved in 1.9.2