Skip to content

Nx-Expo is ignoring custom resolveRequest function in metro.config.js #30583

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

Open
1 of 4 tasks
finkpong opened this issue Apr 2, 2025 · 0 comments
Open
1 of 4 tasks
Assignees
Labels
scope: react-native Issues relating to React Native type: bug

Comments

@finkpong
Copy link

finkpong commented Apr 2, 2025

Current Behavior

I added a custom resolveRequest block in metro.config.js in an Nx-generated expo app, but it is not being called. See steps to reproduce below

Expected Behavior

That my custom resolveRequest function will be run

GitHub Repo

No response

Steps to Reproduce

  1. Generate an Expo app in an Nx workspace (e.g. npx create-nx-workspace@latest --preset=expo --appName=tempNxExpoApp, then npm install)
  2. Add a custom resolverRequest block in metro.config.js
const customConfig = {
..
  resolver: {
// existing lines from nx-generated app
    assetExts: assetExts.filter((ext) => ext !== 'svg'),
    sourceExts: [...sourceExts, 'cjs', 'mjs', 'svg'],

// add this
    resolveRequest: (contextX, moduleNameX, platformX) => {
      // custom alias replacement logic supposed to go here, but for now we just want to know if this block is called.
      // also add a breakpoint here
      console.log(`============ RUNNING CUSTOM RESOLVEREQUEST ============`);

      // call default resolveRequest:
      return contextX.resolveRequest(
        contextX,
        moduleNameX,
        platformX
      );
    },
  },
};
  1. Add a breakpoint in node_modules/@expo/cli/build/src/start/server/metro/withMetroResolvers.js, the following lines:

debug line

debug(`Appending ${resolvers.length} custom resolvers to Metro config. (has custom resolver: ${!!((ref = config.resolver) == null ? void 0 : ref.resolveRequest)})`);

loop

            for (const resolver of resolvers) {
              try {
                const res = resolver(ctx, moduleName, platform);
                if (res) {
                  return res;
                ...
  1. Run the app (start task) with debug enabled (EXPO_DEBUG=true)

Expectation:

  • the [debug] breakpoint will be hit, debug line printed
  • the [loop] breakpoint will be hit, among them is my custom resolver function
  • the breakpoint in my custom resolver code will be hit

Actual:

  • the [debug] breakpoint is hit, debug line printed, saying there are 7 custom resolvers
expo:metro:withMetroResolvers Appending 7 custom resolvers to Metro config. (has custom resolver: true) +0ms
  • the [loop] breakpoint is hit, the resolvers list contains 7 items, none of which is my custom resolver function (with the X suffix in the arg names)
  • the breakpoint in my custom resolver code is not hit

Nx Report

NX   Report complete - copy this into the issue template

Node           : 23.8.0
OS             : darwin-x64
Native Target  : x86_64-macos
npm            : 10.9.2

nx (global)            : 20.4.6
nx                     : 20.7.0
@nx/js                 : 20.7.0
@nx/jest               : 20.7.0
@nx/eslint             : 20.7.0
@nx/workspace          : 20.7.0
@nx/devkit             : 20.7.0
@nx/expo               : 20.7.0
@nx/module-federation  : 20.7.0
@nx/react              : 20.7.0
@nx/web                : 20.7.0
@nx/webpack            : 20.7.0
typescript             : 5.7.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/expo/plugin
---------------------------------------
Cache Usage: 0.00 B / 93.15 GB

Failure Logs

Package Manager Version

10.9.2

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@jaysoo jaysoo added the scope: react-native Issues relating to React Native label Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: react-native Issues relating to React Native type: bug
Projects
None yet
Development

No branches or pull requests

3 participants