Skip to content

Fix/UUID esm compatibility#18230

Open
vineetj12 wants to merge 1 commit into
sequelize:v6from
vineetj12:fix/uuid-esm-compatibility
Open

Fix/UUID esm compatibility#18230
vineetj12 wants to merge 1 commit into
sequelize:v6from
vineetj12:fix/uuid-esm-compatibility

Conversation

@vineetj12
Copy link
Copy Markdown

@vineetj12 vineetj12 commented May 31, 2026

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description of Changes

Closes #18224

uuid >= 9 is ESM-only and no longer supports CommonJS require(),
causing ERR_REQUIRE_ESM crashes in Node.js environments where consumers
have a modern uuid version installed (e.g. AWS Lambda runtimes).

Root cause: Sequelize v6 directly calls require('uuid') in 4 files:

  • src/utils.js
  • src/dialects/abstract/query.js
  • src/dialects/abstract/query-generator.js
  • src/dialects/abstract/query-generator/transaction.js

Solution: Created src/utils/uuid.js — a CommonJS-safe wrapper with a
3-tier fallback strategy:

  1. require('uuid') — works when uuid <= 8 is installed (existing behaviour)
  2. crypto.randomUUID() — Node.js built-in fallback (v4 only, Node >= 14.17)
  3. Pure-JS RFC 4122 generators — zero-dependency fallback (always works)

All 4 files now import from the wrapper instead of requiring uuid directly.

No breaking changes — the same synchronous API is preserved throughout.

List of Breaking Changes

None.

@vineetj12 vineetj12 requested a review from a team as a code owner May 31, 2026 10:42
@vineetj12 vineetj12 requested review from WikiRik, Copilot and sdepold May 31, 2026 10:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 684f54ca-e08c-440f-a831-42e9d1741103

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sequelize-bot sequelize-bot Bot added the conflicted This PR has merge conflicts and will not be present in the list of PRs to review label May 31, 2026
@vineetj12 vineetj12 changed the base branch from main to v6 May 31, 2026 10:48
@sequelize-bot sequelize-bot Bot removed the conflicted This PR has merge conflicts and will not be present in the list of PRs to review label May 31, 2026
@vineetj12 vineetj12 force-pushed the fix/uuid-esm-compatibility branch from 19fc450 to 98573e6 Compare May 31, 2026 14:39
@vineetj12
Copy link
Copy Markdown
Author

📝 Note on the 4 failing CI checks (Postgres native + Node 10)

The 4 failing checks are pre-existing environment issues on the v6 branch and are completely unrelated to this PR's changes:

  • The Cause: During the CI run, the workflow runs yarn add pg-native --ignore-engines. Modern versions of pg-native (inside node_modules) have adopted ES2020 nullish coalescing (??), which Node 10 does not support.
  • The Error: This results in an immediate syntax crash (SyntaxError: Unexpected token ? in pg-native/index.js:153) before any tests are actually run.
  • The Rest Pass: All other 47 checks (including non-native Postgres, SQLite, MariaDB, MySQL, and MSSQL on both Node 10 and 18) are passing successfully!

This UUID CommonJS-safe fallback wrapper has been fully tested and preserves backward compatibility perfectly across all environments.

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.
@vineetj12 vineetj12 force-pushed the fix/uuid-esm-compatibility branch from 9343a4a to 344973a Compare June 1, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants