Skip to content

Fix import of ESM-only module for CJS builds with type: "module"#83

Closed
jpwilliams wants to merge 6 commits into
mainfrom
fix/cjs-esm-import
Closed

Fix import of ESM-only module for CJS builds with type: "module"#83
jpwilliams wants to merge 6 commits into
mainfrom
fix/cjs-esm-import

Conversation

@jpwilliams
Copy link
Copy Markdown
Member

Summary

Following #76, due to "type": "module", CJS struggles to import ESM-only modules. This results in issues like #81 and #82 where we fail to import:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/zander/Documents/Code/goaltime/node_modules/@dmitryrechkin/json-schema-to-zod/dist/index.js from /Users/zander/Documents/Code/goaltime/node_modules/@inngest/agent-kit/dist/index.cjs not supported.
Instead change the require of index.js in /Users/zander/Documents/Code/goaltime/node_modules/@inngest/agent-kit/dist/index.cjs to a dynamic import() which is available in all CommonJS modules.
    at Module._load (/Users/zander/Documents/Code/goaltime/node_modules/@nx/js/src/executors/node/node-with-require-overrides.js:18:31)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at Object.<anonymous> (/Users/zander/Documents/Code/goaltime/node_modules/@inngest/agent-kit/dist/index.cjs:71:33)

This attempts to fix by shifting use of the ESM-only module to a dynamic import.

Related

@jpwilliams jpwilliams added the bug Something isn't working label Mar 4, 2025
@jpwilliams jpwilliams self-assigned this Mar 4, 2025
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 4, 2025

🦋 Changeset detected

Latest commit: ae8f155

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@inngest/agent-kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@inngest-release-bot
Copy link
Copy Markdown
Contributor

inngest-release-bot commented Mar 4, 2025

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@inngest/agent-kit 0.5.2-alpha-20250318145118-233593af723fa8736fdc53804c6d8f1183706e7e npm ↗︎ unpkg ↗︎

@MonsterDeveloper
Copy link
Copy Markdown
Contributor

I've checked out the code for this library as I wanted to open a PR to it with a fix for CJS/ESM, but it doesn't seem be maintained...

Have you considered dropping it in favor of a custom utility (which would probably be ~300 LOC) or using an established library (if any)?

@jpwilliams
Copy link
Copy Markdown
Member Author

@jpwilliams jpwilliams closed this Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

6 participants