Skip to content

fix: re-enable CLI bundle by routing import.meta through package name#141

Open
Mkassabov wants to merge 2 commits into
mainfrom
fix/cli-bundle-import-meta
Open

fix: re-enable CLI bundle by routing import.meta through package name#141
Mkassabov wants to merge 2 commits into
mainfrom
fix/cli-bundle-import-meta

Conversation

@Mkassabov
Copy link
Copy Markdown
Contributor

@Mkassabov Mkassabov commented May 1, 2026

#135 disabled the bin/alchemy.ts tsdown bundle because relative import.meta.* references inside the CLI's import graph misresolve once inlined into bin/alchemy.js — they point at the bundle, not the original source file.

This applies the #128 pattern (import.meta.resolve("alchemy/...") + matching exports entries) to the two real offenders, then re-enables the tsdown config so react/ink/pathe stay out of consumer-visible runtime deps.

  • Cloudflare/Local/Sidecar.ts — package-name resolve SidecarServer.ts instead of ./SidecarServer.ts.
  • Cloudflare/StateStore/Api.ts — package-name resolve Api.ts instead of import.meta.filename. The bundled value is bin/alchemy.js, which has no default export and breaks the worker bundler with [MISSING_EXPORT] "default" is not exported by "bin/alchemy.js".
  • package.json — export ./Cloudflare/Local/SidecarServer.ts and ./Cloudflare/StateStore/Api.ts.
  • tsdown.config.ts — uncomment bin/alchemy.ts entry; document the import.meta constraint inline.

Agent/util/parser.ts also uses import.meta.url but isn't in the CLI bundle's import graph (only reached via Bundle/Docker.ts), so it's left alone.

PR #135 disabled the bin/alchemy.ts tsdown bundle because relative
import.meta.* references inside the CLI's import graph misresolve once
the modules are inlined into bin/alchemy.js (they end up pointing at
the bundle, not the original source file).

Apply the PR #128 pattern (import.meta.resolve("alchemy/...") +
matching exports entries) to the two real offenders pulled into the
CLI bundle, then re-enable the tsdown config so react/ink/pathe stay
out of runtime dependencies:

- Cloudflare/Local/Sidecar.ts: package-name-resolve SidecarServer.ts
  instead of "./SidecarServer.ts" relative to import.meta.url
- Cloudflare/StateStore/Api.ts: package-name-resolve Api.ts instead
  of import.meta.filename (the bundled value would be bin/alchemy.js,
  which has no default export and breaks the worker bundler)
- package.json: export the two newly-referenced source paths
- tsdown.config.ts: uncomment bin/alchemy.ts entry, with a comment
  documenting the import.meta constraint for future bundle additions
@alchemy-version-bot
Copy link
Copy Markdown
Contributor

alchemy-version-bot Bot commented May 1, 2026

Install the packages built from this commit:

alchemy

bun add alchemy@https://pkg.ing/alchemy/6416d6d

@alchemy.run/better-auth

bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/6416d6d

@alchemy.run/pr-package

bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/6416d6d

@alchemy-version-bot
Copy link
Copy Markdown
Contributor

alchemy-version-bot Bot commented May 1, 2026

Website Preview Deployed

URL: https://alchemyeffectwebsite-worker-pr-141-l2o7tfwuhibm4spw.testing-2b2.workers.dev

Built from commit 6416d6d.


This comment updates automatically with each push.

@Mkassabov Mkassabov marked this pull request as draft May 1, 2026 11:03
@Mkassabov Mkassabov marked this pull request as ready for review May 1, 2026 11:12
@Mkassabov Mkassabov requested review from john-royal and sam-goodwin and removed request for john-royal May 1, 2026 11:12
Comment on lines 247 to -249
"./bin/alchemy.js": "./bin/alchemy.js",
"./bin/exec.ts": "./bin/exec.ts",
"./bin/exec.js": "./bin/exec.js"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do we export these?

Api.ts is itself a Cloudflare Worker — the same module that holds the
`main: ...` config gets shipped as the worker after deploy. The previous
top-level `import.meta.resolve(...)` call evaluated in the Workers
runtime too, where `resolve` isn't a function, throwing
`(intermediate value).resolve is not a function` at script startup.

Guard the call with `typeof import.meta.resolve === "function"` and
fall back to `import.meta.filename` in Workers (the value is unused
there — the worker bundler already consumed `main` at deploy time).
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