Skip to content

Fix "Dynamic require" error for CommonJS packages in airflow-ts-pack - #75067

Merged
jason810496 merged 2 commits into
apache:mainfrom
Andrushika:Andrushika/ts-package-problem
Oct 25, 2026
Merged

jason810496 merged 2 commits into
apache:mainfrom
Andrushika:Andrushika/ts-package-problem

Conversation

@Andrushika

Copy link
Copy Markdown
Contributor

Why

airflow-ts-pack bundles a TypeScript Dag into one ESM file with esbuild, then runs that file once to read its Dags. When a dependency ships CommonJS for Node, esbuild turns its require("fs") into a shim that throws if no require is in scope, and an ESM file has none. So pack fails with Dynamic require of "fs" is not supported for any Dag that imports such a package. On main, 9 of the 15 common packages I tried fail this way, including yaml, pg, axios, @aws-sdk/client-s3 and dotenv. Users cannot pass esbuild options to airflow-ts-pack, so they cannot work around it.

What

Add an esbuild banner that defines require with createRequire(import.meta.url), the usual workaround from evanw/esbuild#1921. With it, all 15 packages pack and run.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5.5)

Generated-by: Claude Code (Opus 5.5) following the guidelines

@Andrushika Andrushika changed the title Fix airflow-ts-pack for CommonJS packages using Node built-ins Fix "Dynamic require" error for CommonJS packages in airflow-ts-pack Oct 19, 2026
Comment thread ts-sdk/src/cli/pack.ts Outdated
airflow-ts-pack outputs an ESM bundle, and an ESM file has no
`require`. esbuild turns a CommonJS dependency's `require("fs")` into
a shim that throws `Dynamic require of "fs" is not supported` unless a
`require` is in scope. So any Dag importing such a package (yaml, pg,
axios, @aws-sdk/client-s3, ...) failed to pack, and users cannot pass
esbuild options to work around it.
@Andrushika
Andrushika force-pushed the Andrushika/ts-package-problem branch from 2b206cb to 83a547d Compare October 21, 2026 12:53

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice catch, I verified locally, it's indeed a error we need to fix, thanks.

@jason810496 jason810496 added the backport-to-v3-4-test Backport to v3-4-test label Oct 25, 2026
@jason810496 jason810496 added this to the Airflow 3.4.0 milestone Oct 25, 2026
@jason810496
jason810496 enabled auto-merge (squash) October 25, 2026 06:10
@Andrushika

Copy link
Copy Markdown
Contributor Author

Hi @jason810496 could you please help rebase this?
Seems like the auto merge is stuck. It's because this PR's last CI run was before the auto-merge PR merged. Since auto-merge would be disabled if I rebase myself, could you please help?

@jason810496
jason810496 disabled auto-merge October 25, 2026 07:47
@jason810496
jason810496 merged commit 8b2ef80 into apache:main Oct 25, 2026
79 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-4-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-4-test PR Link

jason810496 pushed a commit that referenced this pull request Oct 25, 2026
…low-ts-pack (#75067) (#75603)

* Fix airflow-ts-pack for CommonJS packages using Node built-ins

airflow-ts-pack outputs an ESM bundle, and an ESM file has no
`require`. esbuild turns a CommonJS dependency's `require("fs")` into
a shim that throws `Dynamic require of "fs" is not supported` unless a
`require` is in scope. So any Dag importing such a package (yaml, pg,
axios, @aws-sdk/client-s3, ...) failed to pack, and users cannot pass
esbuild options to work around it.

* Move the require banner comment onto the esbuild option
(cherry picked from commit 8b2ef80)

Co-authored-by: Andrew Chang <69671930+Andrushika@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants