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

Metro resolver failed with the latest react-native #18724

Closed
1 of 4 tasks
moonjava2005 opened this issue Aug 19, 2023 · 13 comments
Closed
1 of 4 tasks

Metro resolver failed with the latest react-native #18724

moonjava2005 opened this issue Aug 19, 2023 · 13 comments
Assignees
Labels
outdated scope: react-native Issues relating to React Native type: bug

Comments

@moonjava2005
Copy link

moonjava2005 commented Aug 19, 2023

Current Behavior

After I migrate to the Nx latest, when I run iOS simulator, I got this error
Now I'm not able to start the app

BUNDLE src/main.tsx

error: Error: Cannot resolve url
at /ABC/node_modules/@nx/react-native/plugins/metro-resolver.js:31:15
at Object.resolve (/ABC/node_modules/react-native/node_modules/metro-resolver/src/resolve.js:47:12)
at ModuleResolver.resolveDependency (/ABC/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:79:31)
at DependencyGraph.resolveDependency (/ABC/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph.js:277:43)
at Object.resolve (/ABC/node_modules/react-native/node_modules/metro/src/lib/transformHelpers.js:169:21)
at Graph._resolveDependencies (/ABC/node_modules/react-native/node_modules/metro/src/DeltaBundler/Graph.js:473:35)
at Graph._processModule (/ABC/node_modules/react-native/node_modules/metro/src/DeltaBundler/Graph.js:261:38)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Graph._addDependency (/ABC/node_modules/react-native/node_modules/metro/src/DeltaBundler/Graph.js:372:20)
at async Promise.all (index 2)

Then, I tried to install url module, I got another error with error: Error: Cannot resolve http. Finally, I tried to install http but the metro always show error: Error: Cannot resolve http

Expected Behavior

Expected the metro resolver runs smoothly

GitHub Repo

No response

Steps to Reproduce

  1. npx nx migrate latest
  2. yarn install
  3. npx nx migrate --run-migrations

Nx Report

Node   : 18.14.2
   OS     : darwin-arm64
   yarn   : 1.22.19

   nx                 : 16.7.2
   @nx/js             : 16.7.2
   @nx/jest           : 16.7.2
   @nx/linter         : 16.7.2
   @nx/workspace      : 16.7.2
   @nx/detox          : 16.7.2
   @nx/devkit         : 16.7.2
   @nx/eslint-plugin  : 16.7.2
   @nx/nest           : 16.7.2
   @nx/node           : 16.7.2
   @nx/react          : 16.7.2
   @nx/react-native   : 16.7.2
   @nrwl/tao          : 16.7.2
   @nx/web            : 16.7.2
   @nx/webpack        : 16.7.2
   nx-cloud           : 16.4.0-beta.1
   typescript         : 5.1.6

Failure Logs

BUNDLE src/main.tsx

error: Error: Cannot resolve url
at /ABC/node_modules/@nx/react-native/plugins/metro-resolver.js:31:15
at Object.resolve (/ABC/node_modules/react-native/node_modules/metro-resolver/src/resolve.js:47:12)
at ModuleResolver.resolveDependency (/ABC/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:79:31)
at DependencyGraph.resolveDependency (/ABC/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph.js:277:43)
at Object.resolve (/ABC/node_modules/react-native/node_modules/metro/src/lib/transformHelpers.js:169:21)
at Graph._resolveDependencies (/ABC/node_modules/react-native/node_modules/metro/src/DeltaBundler/Graph.js:473:35)
at Graph._processModule (/ABC/node_modules/react-native/node_modules/metro/src/DeltaBundler/Graph.js:261:38)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Graph._addDependency (/ABC/node_modules/react-native/node_modules/metro/src/DeltaBundler/Graph.js:372:20)
at async Promise.all (index 2)

Operating System

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

Additional Information

No response

@AgentEnder AgentEnder added the scope: react-native Issues relating to React Native label Aug 21, 2023
@toni1703
Copy link

toni1703 commented Aug 29, 2023

I had the same problem too when migrating, did not resolved it!

@jael0x
Copy link

jael0x commented Aug 30, 2023

Same problem here, may be related to this issue:
React Native Metro: Ignoring packages during dependency resolution #18612

Maybe a patch like this could work for now?
facebook/metro#519 (comment)

Help please!

@airowe
Copy link

airowe commented Sep 1, 2023

I'm getting the same error, stopping me from upgrading an entire monorepo

@daviaugustos
Copy link

Same issue here!

@airowe
Copy link

airowe commented Sep 22, 2023

@moonjava2005 Were you able to find a solution for this?

@Bengejd
Copy link

Bengejd commented Sep 25, 2023

Also encountering this issue...

@MrGru
Copy link

MrGru commented Sep 26, 2023

I update the metro.config.js with
unstable_enablePackageExports: false
and it works for me
image

@jpaas
Copy link

jpaas commented Sep 26, 2023

We're using node.js 18, and for us it is the unstable_enablePackageExports that causes this problem. unstable_enableSymlinks seems to work fine.

@airowe
Copy link

airowe commented Sep 26, 2023

Metro can't find any of my third party modules that are symlinked. I tried the above unstable config options, to no avail. Even if I change the reference to the root of my monorepo, the modules still can't be found when building my react-native project.

@alexbalda
Copy link

Facing the same issue as well. In my case, turning off unstable_enablePackageExports sends Metro in to an infinite loop. I am blocked from upgrading React Native to the latest version.

@xiongemi xiongemi self-assigned this Oct 4, 2023
@xiongemi
Copy link
Collaborator

xiongemi commented Oct 4, 2023

form the error, i think it is related to facebook/react-native#38025. the suggestion is to comment out unstable_enablePackageExports: true,. i comment out the line unstable_enablePackageExports: true, and it seems to resolve the node.js module. this is my metro.config.js:

const { withNxMetro } = require('@nx/react-native');
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
const exclusionList = require('metro-config/src/defaults/exclusionList');

const defaultConfig = getDefaultConfig(__dirname);
const { assetExts, sourceExts } = defaultConfig.resolver;

/**
 * Metro configuration
 * https://facebook.github.io/metro/docs/configuration
 *
 * @type {import('metro-config').MetroConfig}
 */
const customConfig = {
  transformer: {
    babelTransformerPath: require.resolve('react-native-svg-transformer'),
  },
  resolver: {
    assetExts: assetExts.filter((ext) => ext !== 'svg'),
    sourceExts: [...sourceExts, 'svg'],
    blockList: exclusionList([/^(?!.*node_modules).*\/dist\/.*/]),
    unstable_enableSymlinks: true,
    // unstable_enablePackageExports: true,
  },
};

module.exports = withNxMetro(mergeConfig(defaultConfig, customConfig), {
  // Change this to true to see debugging info.
  // Useful if you have issues resolving modules
  debug: true,
  // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx', 'json'
  extensions: [],
  // Specify folders to watch, in addition to Nx defaults (workspace libraries and node_modules)
  watchFolders: [],
});

@xiongemi
Copy link
Collaborator

closing this issue for now

Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: react-native Issues relating to React Native type: bug
Projects
None yet
Development

No branches or pull requests