Skip to content

Declare dependencies required by published TypeScript types - #2149

Merged
robhogan merged 2 commits into
react:mainfrom
sorinc03:fix/publish-required-type-dependencies
Nov 20, 2026
Merged

robhogan merged 2 commits into
react:mainfrom
sorinc03:fix/publish-required-type-dependencies

Conversation

@sorinc03

@sorinc03 sorinc03 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Published Metro declarations import external type packages and internal Metro packages that consumers could previously obtain only through development dependencies or accidental hoisting. Clean TypeScript consumers can fail with TS7016 or TS2307 errors.

Declare those dependencies in the packages that import them, preserve existing runtime constraints, and use the genuine @types/source-map@0.5.2 declarations for the unchanged source-map 0.5 runtime. This includes the direct dependencies used by metro-config and metro-core in non-hoisted installations.

Fixes #2135. This addresses published declarations; #2116 concerns the monorepo's development dependencies.

Changelog: [Fix] Include dependencies required by Metro's published TypeScript declarations

Test plan

  • Original clean npm consumer repros: 14 public-import TS7016 errors and 20 all-declaration TS7016 errors become zero.
  • Freshly build and pack all 17 packages. With the reviewed PR head, a strict TypeScript 6.0.3 consumer of metro and metro-config with pnpm hoisting disabled reports four TS2307 errors. With the additional direct dependencies, the same consumer passes. The default-hoisting baseline control also passes.
  • The non-hoisted test uses skipLibCheck: false, no NODE_PATH or TypeScript path mappings, and local tarball overrides for all Metro packages.
  • All 17 tarballs compared across the direct-dependency follow-up: only metro-config/package.json and metro-core/package.json differ; runtime and declaration bytes are identical. The complete dependency-cycle partition is unchanged.
  • Full final repository checks pass: Flow, lint, Markdown lint, format, declaration/build generation, 162 Jest suites, 3,059 tests, and 495 snapshots; 14 existing skips.
  • yarn typecheck-ts, frozen Yarn and pnpm installs, and diff checks pass. The original five-line lock entry is retained; the internal-package additions need no lock change.

Validation uses a temporary staging path without types to avoid the independently reproduced generator-path bug tracked by #2148. That fix and other unrequested reverse dependency edges are outside this PR.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Metro review: Looks good

Risk: low · Commit: 41ac020 · unvetted author, reviewed from source only

This PR moves the type packages that Metro's published declarations import (@types/babel__core, @types/babel__traverse, @babel/types, @types/connect, @types/ws, @types/yargs and @types/source-map@0.5.2) into the runtime dependencies of the packages that import them. The head is back to the original scope and no longer adds the internal metro-core/metro-config edges, so both earlier nits about those edges no longer apply. I found nothing new. The package.json and yarn.lock changes need a Meta import.

No findings.

Not run: Nothing was run. A maintainer has taken over the PR and asked for no more bot reviews, so this pass only rechecked the earlier findings against the current head. I also checked from source that each new dependency matches an import in the package's Flow sources, such as source-map in metro-symbolicate and @babel/types/@babel/traverse in metro-transform-plugins. Not benchmarked: this changes only dependency manifests.

Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call.

},
"license": "MIT",
"dependencies": {
"@types/connect": "^3.4.35",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit · Non-hoisted installs still fail on undeclared metro-* imports in metro-config and metro-core

The PR aims to stop published declarations relying on packages that are only available accidentally through transitive dependencies, but the same pattern remains for some internal packages. It isn't a regression, and npm and default pnpm installs aren't affected.

Failure case: a strict TypeScript consumer of metro and metro-config, installed with pnpm hoist: false, gets 4 TS2307 errors at head:

  • metro-config/src/types.d.ts can't find metro-file-map, metro-resolver or metro-transform-worker.
  • metro-core/src/errors/AmbiguousModuleResolutionError.d.ts can't find metro-file-map.

Fix: add these as dependencies of metro-config and metro-core, here or in a follow-up. An import audit of the declarations also flags metro-core to metro, metro-file-map to metro-config and metro-minify-terser to metro-transform-worker. Those would add new links between Metro's packages, so they may need a maintainer decision. They didn't produce errors in this consumer.

Reproduced: Packed head tarballs and installed them in a fresh pnpm 12 consumer with hoist: false. tsc -p . with TypeScript 6.0.3, strict and skipLibCheck: false exited 2 with exactly these 4 TS2307 errors. The same head tarballs pass under default pnpm hoisting. The PR doesn't change these imports or add these dependencies; the failure wasn't run against base. · id 0cfa611c

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added all four direct dependencies in faba463: metro-config now declares metro-file-map, metro-resolver, and metro-transform-worker; metro-core declares metro-file-map. Each uses the existing 0.87.2 workspace version, with no lockfile change.

Freshly built and packed head tarballs reproduce exactly the four TS2307 errors in a strict TypeScript consumer with pnpm hoisting disabled. The same consumer passes with the new manifests; the default-hoisting baseline control also passes. Comparing all 17 tarballs shows only these two package manifests changed.

The config → transform-worker edge stays within the existing config → metro → transform-worker dependency component; the complete strongly connected component partition is unchanged. Other reverse edges noted in the comment remain outside this change.

Validation: frozen Yarn and pnpm installs; full repository checks (162 suites, 3059 tests, 495 snapshots passed; 14 existing skips); and yarn typecheck-ts pass.

@robhogan

robhogan commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks @sorinc03

Apologies for the noisy review bot, I think your original version of this PR was probably best tbh.

I’ll take it from here. Review bot: no more please

# Conflicts:
#	packages/metro-config/package.json
@robhogan
robhogan force-pushed the fix/publish-required-type-dependencies branch from faba463 to 41ac020 Compare November 20, 2026 17:12

@robhogan robhogan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks again!

@robhogan
robhogan merged commit fb050a0 into react:main Nov 20, 2026
16 checks passed
robhogan added a commit that referenced this pull request Nov 20, 2026
#2149 declared the third-party packages our generated TypeScript definitions import, but eight type-only imports between Metro packages are still undeclared (eg `metro-core` imports `BundleOptions` from `metro`). Under strict installs these fail with TS2307 unless the consumer sets `skipLibCheck`.

Rather than add dependencies that only exist for types, some of them circular, this removes the imports. Small structural types are duplicated where they're used, `metro-config` imports from `metro`'s entry point, and `ResolutionContext.dependency` becomes a minimal `Dependency` (`name`, `data.key`, `data.locs`, `data.asyncType`) instead of `TransformResultDependency`.

Typed callers may need an annotation:
 - `bundle_options` moves from `metro-core`'s `LogEntry` to `MetroLogEntry`, exported by `metro`. Annotate handlers that read it: `Logger.on('log', (entry: MetroLogEntry) => ...)`.
 - `AmbiguousModuleResolutionError#hasteError` is a structural interface, no longer assignable to `DuplicateHasteCandidatesError`.
 - Custom resolvers can't read other fields of `context.dependency.data` (use `context.isESMImport`) or pass it on as a `TransformResultDependency`.
 - `MinifierResult.map` and `decodedMap` are read-only.

Changelog:
```
 - **[Types]**: Remove undeclared type-only imports between Metro packages. `bundle_options` moves from `metro-core`'s `LogEntry` to `MetroLogEntry`, exported by `metro` - annotate `Logger.on` handlers that read it as `(entry: MetroLogEntry) => ...`
```
robhogan added a commit that referenced this pull request Nov 21, 2026
#2149 declared the third-party packages our generated TypeScript definitions import, but eight type-only imports between Metro packages are still undeclared (eg `metro-core` imports `BundleOptions` from `metro`). Under strict installs these fail with TS2307 unless the consumer sets `skipLibCheck`.

Rather than add dependencies that only exist for types, some of them circular, this removes the imports. Small structural types are duplicated where they're used, `metro-config` imports from `metro`'s entry point, and `ResolutionContext.dependency` becomes a minimal `Dependency` (`name`, `data.key`, `data.locs`, `data.asyncType`) instead of `TransformResultDependency`.

Typed callers may need an annotation:
 - `bundle_options` moves from `metro-core`'s `LogEntry` to `MetroLogEntry`, exported by `metro`. Annotate handlers that read it: `Logger.on('log', (entry: MetroLogEntry) => ...)`.
 - `AmbiguousModuleResolutionError#hasteError` is a structural interface, no longer assignable to `DuplicateHasteCandidatesError`.
 - Custom resolvers can't read other fields of `context.dependency.data` (use `context.isESMImport`) or pass it on as a `TransformResultDependency`.
 - `MinifierResult.map` and `decodedMap` are read-only.

Changelog:
```
 - **[Types]**: Remove undeclared type-only imports between Metro packages. `bundle_options` moves from `metro-core`'s `LogEntry` to `MetroLogEntry`, exported by `metro` - annotate `Logger.on` handlers that read it as `(entry: MetroLogEntry) => ...`
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. needs-meta-import

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Published declarations import types from connect, @babel/core and @babel/traverse, whose @types packages are not dependencies

2 participants