zhe-qi opened a new issue, #562: URL: https://github.com/apache/casbin-node-casbin/issues/562
## Summary The npm package `casbin` appears to expose a broken native Node ESM entry in `v5.51.0`. In `v5.51.0`, `package.json` added an `exports.import` entry pointing to `./lib/esm/index.js`. That ESM entry contains extensionless/directory relative imports such as `./util`, which native Node ESM does not resolve as `./util/index.js`. This causes Vite SSR / Node ESM projects to fail during module resolution. ## Environment - casbin: 5.51.0 - Node.js: v26.1.0 - pnpm: 11.9.0 - Project type: ESM (`"type": "module"`) - Runtime/bundler: Vite SSR / native Node ESM ## Reproduction ```bash mkdir casbin-esm-repro cd casbin-esm-repro pnpm init pnpm add [email protected] node --input-type=module -e "import('casbin')" ``` ## Actual behavior ```text ERR_UNSUPPORTED_DIR_IMPORT Directory import '.../node_modules/casbin/lib/esm/util' is not supported resolving ES modules imported from .../node_modules/casbin/lib/esm/index.js ``` In our Vite dev server, the same failure appears as: ```text [vite] Internal server error: Directory import '.../node_modules/.pnpm/[email protected]/node_modules/casbin/lib/esm/util' is not supported resolving ES modules imported from .../node_modules/.pnpm/[email protected]/node_modules/casbin/lib/esm/index.js ``` ## Expected behavior `import('casbin')` should work in native Node ESM, or the package should not expose a broken ESM entry via `exports.import`. ## Suspected cause `[email protected]` exposes: ```json { "exports": { ".": { "types": "./lib/cjs/index.d.ts", "import": "./lib/esm/index.js", "require": "./lib/cjs/index.js" } } } ``` But `lib/esm/index.js` contains imports like: ```js import * as Util from './util'; export * from './config'; export * from './enforcer'; ``` Native Node ESM requires fully specified relative file paths and does not support directory index resolution for `./util`. `[email protected]` did not have the `exports` field, so tools could resolve the package through the CJS `main` entry. After `v5.51.0`, ESM consumers are forced onto `./lib/esm/index.js` and hit this error. ## Workaround For now, forcing CommonJS works: ```js import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); const casbin = require('casbin'); ``` ## Possible fix Generate/publish ESM output with fully specified relative imports, for example `./util/index.js`, `./config.js`, etc., or remove/adjust `exports.import` until the ESM build is compatible with native Node ESM. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
