Repository navigation
Conversation
If `fileMapCacheDirectory` points at a directory that doesn't exist yet, the file map cache is never written, so every restart crawls the project from scratch. The only sign is a warning at startup: ``` [metro-file-map] Cache write error : Error: ENOENT: no such file or directory, open '/path/to/project/node_modules/.cache/metro-file-map/metro-file-map-<hash>-<hash>' ``` The default, `os.tmpdir()`, always exists, so this only affects a custom directory - but a project-local one like `node_modules/.cache/metro-file-map` won't exist on a fresh checkout or after `node_modules` is removed. The transform cache doesn't have this problem, because `FileStore` creates its directory when a write fails with `ENOENT`. This change does the same in `DiskCacheManager`: on `ENOENT`, create the directory (recursively) and retry the write once. Writes into an existing directory are unchanged. > [!NOTE] > Found in an Expo SDK 57 app. Expo CLI uses its fork, `@expo/metro-file-map`, which has the same `writeFile` in `DiskCacheManager.ts`, so it'll need the same change. Changelog: ``` - **[Fix]**: Create `fileMapCacheDirectory` if it doesn't exist, rather than failing to persist the file map cache ``` Test plan: New test in `DiskCacheManager-test.js` where the first write fails with `ENOENT`, asserting that the directory is created and the snapshot written without an error. It fails before this change and passes after. A second test checks that other errors, e.g. `EACCES`, are still reported without a retry. Also checked end-to-end with `createFileMap` and `fileMapCacheDirectory` set to a missing `<project>/node_modules/.cache/metro-file-map`: before, the warning above and no directory; after, no warning and the cache file is written. ``` yarn jest packages/metro-file-map packages/metro/src/node-haste packages/metro/src/DeltaBundler yarn flow check yarn eslint packages/metro-file-map yarn verify-api-snapshots ``` Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shubh73
force-pushed
the
file-map-cache-directory
branch
from
October 23, 2026 19:42
8e5c936 to
aa11861
Compare
This branch has not been deployed
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.
If
fileMapCacheDirectorypoints at a directory that doesn't exist yet, the file map cache is never written, so every restart crawls the project from scratch. The only sign is a warning at startup:The default,
os.tmpdir(), always exists, so this only affects a custom directory - but a project-local one likenode_modules/.cache/metro-file-mapwon't exist on a fresh checkout or afternode_modulesis removed. The transform cache doesn't have this problem, becauseFileStorecreates its directory when a write fails withENOENT.This change does the same in
DiskCacheManager: onENOENT, create the directory (recursively) and retry the write once. Writes into an existing directory are unchanged.Note
Found in an Expo SDK 57 app. Expo CLI uses its fork,
@expo/metro-file-map, which has the samewriteFileinDiskCacheManager.ts, so it'll need the same change.Changelog:
Test plan:
New test in
DiskCacheManager-test.jswhere the first write fails withENOENT, asserting that the directory is created and the snapshot written without an error. It fails before this change and passes after. A second test checks that other errors, e.g.EACCES, are still reported without a retry.Also checked end-to-end with
createFileMapandfileMapCacheDirectoryset to a missing<project>/node_modules/.cache/metro-file-map: before, the warning above and no directory; after, no warning and the cache file is written.馃 Generated with Claude Code