Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support serverRoot with hmr serializer chunks #1137

Conversation

EvanBacon
Copy link
Contributor

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.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Nov 11, 2023
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e2d6419) 83.09% compared to head (a7ae0d4) 83.09%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1137   +/-   ##
=======================================
  Coverage   83.09%   83.09%           
=======================================
  Files         206      206           
  Lines       10549    10550    +1     
  Branches     2619     2620    +1     
=======================================
+ Hits         8766     8767    +1     
  Misses       1783     1783           
Files Coverage Δ
.../metro/src/DeltaBundler/Serializers/hmrJSBundle.js 82.92% <100.00%> (+0.42%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@facebook-github-bot
Copy link
Contributor

@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@robhogan
Copy link
Contributor

robhogan commented Nov 20, 2023

Apologies for the delay with this, I wanted to try this to make sure I understood how it all fits together - can confirm the root cause is incorrectly generated source (map) URLs, and this LGTM.

Before

image

After

image

@robhogan
Copy link
Contributor

We use unstable_serverRoot heavily in Expo to support monorepos

I'm keen to promote some of these unstable_ features to stable given how load-bearing Expo's use makes them, but tbh I'm not totally sure what the concrete use case is for serverRoot in new projects.

Why not set projectRoot to the workspace root instead?

@facebook-github-bot
Copy link
Contributor

@robhogan merged this pull request in 402dc0b.

@EvanBacon EvanBacon deleted the @evanbacon/fix-server-root-in-hmr-serializer branch November 21, 2023 18:08
robhogan pushed a commit that referenced this pull request Jan 9, 2024
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
@robhogan robhogan mentioned this pull request Jan 9, 2024
robhogan pushed a commit that referenced this pull request Jan 9, 2024
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
robhogan pushed a commit that referenced this pull request Jan 30, 2024
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
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. Merged Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants