Fix/UUID esm compatibility#18230
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
19fc450 to
98573e6
Compare
📝 Note on the 4 failing CI checks (
|
Fixes sequelize#18224 uuid >= 9 is ESM-only and no longer supports CommonJS require(), causing ERR_REQUIRE_ESM crashes in Node.js environments using modern uuid versions (AWS Lambda etc). Solution: Created src/utils/uuid.js — a CJS-safe wrapper with three-tier fallback strategy: 1. require('uuid') — works for uuid <= 8 2. crypto.randomUUID() — fallback for uuid >= 9 3. Pure-JS generators — fallback with no dependencies Avoids making UUID generators async which would be a breaking change to Sequelize's public API. Also ensures full Node 10 and Mocha compatibility for the UUID wrapper. Tested with: uuid@8, uuid@10, uuid@11, no uuid installed All unit tests pass. Build compiles successfully. TypeScript checks pass. Node.js v24.4.0 compatible.
9343a4a to
344973a
Compare
Pull Request Checklist
Description of Changes
Closes #18224
uuid>= 9 is ESM-only and no longer supports CommonJSrequire(),causing
ERR_REQUIRE_ESMcrashes in Node.js environments where consumershave a modern
uuidversion installed (e.g. AWS Lambda runtimes).Root cause: Sequelize v6 directly calls
require('uuid')in 4 files:src/utils.jssrc/dialects/abstract/query.jssrc/dialects/abstract/query-generator.jssrc/dialects/abstract/query-generator/transaction.jsSolution: Created
src/utils/uuid.js— a CommonJS-safe wrapper with a3-tier fallback strategy:
require('uuid')— works when uuid <= 8 is installed (existing behaviour)crypto.randomUUID()— Node.js built-in fallback (v4 only, Node >= 14.17)All 4 files now import from the wrapper instead of requiring
uuiddirectly.No breaking changes — the same synchronous API is preserved throughout.
List of Breaking Changes
None.