Search code examples
node.jses6-modulescasl

CaslJS with ESM Node16


I've been using CaslJS (@casl/ability) for a few years now and am now trying to migrate my typescript project from CommonJS to ESM.

I've got my whole project migrated, but CaslJS throws errors about missing declaration files, e.g.:

node_modules/@casl/ability/dist/types/types.d.ts(1,32): error TS7016: Could not find a declaration file for module '@ucast/mongo2js'.

I've done a bit of digging into this, and isolated the problem to the "moduleResolution": "node16" configuration in tsconfig.json.

With this set to node the project builds fine (but the build produces commonjs, not esm)

Any help with fixing these type errors would be appreciated as Casl is now the only blocker to moving to ESM.

I've been able to replicate this in a new example project here: https://github.com/egmacke/rush-examples/tree/master/casljs-esm-node16


Solution

  • This issue has now been resolved. The issue was actually with the @ucast/mongo2js library not exporting it's types correctly.

    For reference, https://github.com/stalniy/casl/issues/734