Skip to content

Commit

Permalink
fix: support serverRoot with hmr serializer chunks (#1137)
Browse files Browse the repository at this point in the history
Summary:
We use unstable_serverRoot heavily in Expo to support monorepos and consistently have issues where saving a file will log an error in the console:

```
Error: Unable to resolve module ./app/index from /Users/evanbacon/Documents/GitHub/expo/.:

None of these files exist:
  * ../../app/index(.web.ts|.ts|.web.tsx|.tsx|.web.mjs|.mjs|.web.js|.js|.web.jsx|.jsx|.web.json|.json|.web.cjs|.cjs|.web.scss|.scss|.web.sass|.sass|.web.css|.css|.web.cjs|.cjs)
  * ../../app/index/index(.web.ts|.ts|.web.tsx|.tsx|.web.mjs|.mjs|.web.js|.js|.web.jsx|.jsx|.web.json|.json|.web.cjs|.cjs|.web.scss|.scss|.web.sass|.sass|.web.css|.css|.web.cjs|.cjs)
    at ModuleResolver.resolveDependency (/Users/evanbacon/Documents/GitHub/expo/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:114:15)
    at DependencyGraph.resolveDependency (/Users/evanbacon/Documents/GitHub/expo/node_modules/metro/src/node-haste/DependencyGraph.js:277:43)
    at /Users/evanbacon/Documents/GitHub/expo/node_modules/metro/src/lib/transformHelpers.js:169:21
    at Server._resolveRelativePath (/Users/evanbacon/Documents/GitHub/expo/node_modules/metro/src/Server.js:1045:12)
    at Server.requestProcessor [as _processSourceMapRequest] (/Users/evanbacon/Documents/GitHub/expo/node_modules/metro/src/Server.js:449:37)
    at Server._processRequest (/Users/evanbacon/Documents/GitHub/expo/node_modules/metro/src/Server.js:396:7)
```

This is because the HMR `sourceMappingURL` is being calculated relative to the projectRoot instead of the serverRoot, but all files are being resolved relative to the serverRoot.

Pull Request resolved: #1137

Test Plan:
[rob]

Before:
{F1154753453}

After:
 {F1154752435}

Reviewed By: huntie

Differential Revision: D51467903

Pulled By: robhogan

fbshipit-source-id: a14ca98a9d95eb18d521b11592b2d251fc09f178
  • Loading branch information
EvanBacon authored and robhogan committed Jan 9, 2024
1 parent 04ed99a commit 2e1377b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/metro/src/DeltaBundler/Serializers/hmrJSBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function generateModules(
// Construct a bundle URL for this specific module only
const getURL = (extension: 'bundle' | 'map') => {
options.clientUrl.pathname = path.relative(
options.projectRoot,
options.serverRoot ?? options.projectRoot,
path.join(
path.dirname(module.path),
path.basename(module.path, path.extname(module.path)) +
Expand Down

0 comments on commit 2e1377b

Please sign in to comment.