Repository navigation
Fix: resolve the browser export condition in core and integrations - #618
Merged
AmaadMartin merged 7 commits intoAug 13, 2026
Merged
AmaadMartin merged 7 commits into
AmaadMartin merged 7 commits into
Conversation
kalenkevich
reviewed
Aug 5, 2026
| "types": "./dist/types/*", | ||
| "default": "./dist/web/*" | ||
| }, | ||
| "./package.json": "./package.json" |
Collaborator
Author
There was a problem hiding this comment.
Good catch — we don't. Removed in 3e5217f, along with the test that covered it.
The exports map predates this PR (it's unchanged context in the hunk), so @google/adk/package.json was already unresolvable on main — require.resolve throws ERR_PACKAGE_PATH_NOT_EXPORTED both before and after the removal, so behaviour now matches main exactly. Nothing in the repo resolves that path, and dev and integrations both declare exports with "." only, so there was no precedent for it either.
The browser condition and the ./dist/web/* subpath are untouched — those are the actual point of the PR.
Collaborator
Author
There was a problem hiding this comment.
Still removed after the rebase onto main; the commit is now b8913f5.
added 6 commits
August 7, 2026 10:53
An "exports" map takes precedence over the legacy top-level "browser" field in every modern bundler, so the field at core/package.json was never consulted: a browser bundler matched "import" and pulled in the Node build under dist/esm, along with fs, path, http and zlib. Declare a "browser" condition on "." -- before "import" and "require", since conditions match in declaration order and a later one would silently never fire -- and keep "types" first so TypeScript still finds the declarations. Because an "exports" map is exhaustive, "." being the only declared subpath also made the web build unreachable by name. Declare "./dist/web/*" (with a "types" condition pointing at dist/types, which is where tsc emits the declarations) and re-expose "./package.json". Node ESM, Node CJS and TypeScript resolution are unchanged. Fixes #610
Guards the invariant a future edit can silently break: the "browser" condition must sit after "types" and before "import" and "require", because conditions match in declaration order and a misplaced one is a no-op that still looks correct in review.
Assert the condition map's value before its key order, so deleting the subpath reports the expected object rather than a TypeError from Object.keys(undefined).
Reviewer asked why it is needed. It is not: core/package.json already declared an "exports" map before this change, so the encapsulation boundary that makes @google/adk/package.json unresolvable predates this PR rather than being introduced by it. Nothing in the repo resolves that specifier, and dev/ and integrations/ declare "." alone, so there is no precedent either. Removing it leaves that specifier exactly as it behaves on main. Drops the accompanying test with it: it only asserted the entry this change had added, so it pinned nothing once the entry is gone.
…xports The exports map shadows the legacy top-level browser field, so a browser bundler resolving @google/adk-integrations lands on the Node ESM build and dist/web is unreachable by name. Mirrors the core manifest.
Replaces the shape-only core/test/package_exports_test.ts, which read the manifest and asserted key order. That test can pass while resolution is broken, and cannot fail when a renamed dist/web file breaks it. The new test spawns Node with an explicit condition set, because every vitest project aliases @google/adk to core/src and would bypass the exports map entirely.
AmaadMartin
force-pushed
the
fix/core-package-exports-browser-condition
branch
from
August 7, 2026 18:05
3e5217f to
5fb12da
Compare
Keeps the helper out of the describe closure, so it takes the package directory as a parameter like the other helpers in this file.
kalenkevich
approved these changes
Aug 13, 2026
Merged
prasanna8585
pushed a commit
to prasanna8585/adk-js
that referenced
this pull request
Aug 21, 2026
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
Link to an existing issue (if applicable):
Closes: package.json
exportshas nobrowsercondition, so bundlers resolve the Node build and thebrowserfield is ignored #610Related: Tracking: @google/adk cannot be bundled for the browser (5 build-level defects) #607
Or, if no issue exists, describe the change:
Problem:
coreandintegrationsboth declare anexportsmap with nobrowsercondition. A bundler treatsexportsas authoritative and stops reading the legacy top-levelbrowserfield, so a browser build matches"import"and gets the Node ESM entry."."is the only declared subpath, so a consumer cannot opt in by hand either. The publisheddist/webtarget is therefore unreachable by name in both packages.Solution: I added a
browsercondition ahead ofimportandrequire, plus a./dist/web/*subpath, to both manifests.typesstays the first condition, so TypeScript resolution does not move. Theintegrationshalf is a no-op for consumers today, because itsindex.tsandindex_web.tsboth export onlyversion; I changed it anyway so the defect cannot come back silently when the two entries diverge.Measured, for
@google/adkand@google/adk-integrationsalike:target: 'web'dist/esm/index.jsdist/web/index_web.jsdist/esm/index.jsdist/web/index_web.jsnode --conditions=browserdist/esm/index.jsdist/web/index_web.jsimportdist/esm/index.jsdist/esm/index.jsrequiredist/cjs/index.jsdist/cjs/index.js<pkg>/dist/web/index_web.jsERR_PACKAGE_PATH_NOT_EXPORTEDThe browser surface shrinks, and that is the intent. A browser bundler now gets
index_web.js, which iscommon.jsonly, instead of the full Node barrel. Nothing that worked stops working: #607 measured 625 errors bundling@google/adkfor the browser today, so there is no working browser consumer to break. The exports that disappear are the ones that could never run in a browser, such asGcsArtifactService,DatabaseSessionServiceand the filesystem skill loaders.Not blocked on #614, and does not block it. #614 fixes the Node built-ins that still leak into
dist/web. This change asserts which file a resolver selects, which only needs that file to exist, so the two are independent and touch disjoint files. One note for whoever lands second: #614 turnsdist/webinto a single bundled file, after which the./dist/web/*subpath stays valid but has little left to address, and its"types": "./dist/types/*"mapping becomes approximate.Changes since the previous revision of this PR. I rebased onto
main, applied the same fix tointegrations/package.json, and replacedcore/test/package_exports_test.tswith a resolution test. That deleted test read the manifest and asserted key order, so it could pass while resolution was broken and could not fail when a renameddist/webfile broke it. Every assertion it made is now covered by resolution instead.Testing Plan
Please describe the tests that you ran to verify your changes. This is required for all PRs that are not small documentation or typo fixes.
Unit Tests:
[x] I have added or updated unit tests for my change.
[x] All unit tests pass locally.
tests/integration/build_setup/package_resolution_test.ts(10 tests, 1.3s) resolves each package in a child Node process and asserts the path. It runs out of process because every vitest project aliases@google/adktocore/src, so an in-process import never consults theexportsmap. It also asserts the resolved browser file exists on disk, becauseimport.meta.resolvedoes not check and a missing target underexportsis a hard bundler error.Mutation checks. Each new assertion was run against unfixed code and confirmed to fail.
browsercondition fromcore/package.jsonExpected: .../core/dist/web/index_web.js,Received: .../core/dist/esm/index.jsbrowsercondition fromintegrations/package.jsonintegrations./dist/web/*from both manifestsError [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/web/index_web.js' is not defined by "exports"core/dist/web/index_web.jsoff diskresolves the browser condition to a file that existsThe last one is the
build:bundlecase:core/build.jsemitsdist/web/index.jsin--bundlemode, notindex_web.js. That is harmless today becauseprepublishOnlyruns the non-bundle build, but after this change it would ship a package that fails to resolve for every browser consumer.Repo checks on the pushed commit:
npm run lintandnpm run format:checkboth pass.npm run ts:checkreports 477 pre-existing errors onmainand 0 in the new file.run-testsis green on ubuntu, macOS and windows for the pushed commit. Earlier runs went red ontests/integration/app_loader/app_loader_test.ts, which times out at 40s. That is the pre-existing flake tracked in #622, and a re-run cleared it.Manual End-to-End (E2E) Tests:
Please provide instructions on how to manually test your changes, including any necessary setup or configuration.
This produced the table above. A stub package copies
name,main,module,browser,typingsandexportsverbatim from each manifest, with eachdistentry replaced by a one-line module naming itself. Stubbing isolates resolution from the bundling defects tracked in #607.Against the real packages, after
npm run build:esbuild now enters
core/dist/web/index_web.js, where before it enteredcore/dist/esm/index.js. It still reports 4 errors for Node built-ins reached from the web entry. That count is the same before and after, and #614 fixes it.Checklist
[x] I have read the CONTRIBUTING.md document.
[x] I have performed a self-review of my own code.
[x] I have commented my code, particularly in hard-to-understand areas.
[x] I have added tests that prove my fix is effective or that my feature works.
[x] New and existing unit tests pass locally with my changes.