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

bundling failed: Error: Unable to resolve module ../Components/AccessibilityInfo/AccessibilityInfo from node_modules/react-native/Libraries/react-native/react-native-implementation.js: #564

Closed
sangeethkumarv opened this issue Aug 28, 2020 · 20 comments

Comments

@sangeethkumarv
Copy link

While running the app in bundler it fails with the following message in the terminal

warning: the transform cache was reset.
Loading dependency graph, done.

To reload the app press "r"
To open developer menu press "d"

error: bundling failed: Error: Unable to resolve module ../Components/AccessibilityInfo/AccessibilityInfo from node_modules/react-native/Libraries/react-native/react-native-implementation.js:

None of these files exist:

  • node_modules/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo(.native|.macos.js|.native.js|.js|.macos.json|.native.json|.json|.macos.ts|.native.ts|.ts|.macos.tsx|.native.tsx|.tsx)
  • node_modules/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo/index(.native|.macos.js|.native.js|.js|.macos.json|.native.json|.json|.macos.ts|.native.ts|.ts|.macos.tsx|.native.tsx|.tsx)
    at ModuleResolver.resolveDependency (/Users/dev/Desktop/Sangeeth/mytakeaway2.0/Myt-Mac/MYT_MacOS/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:163:15)
    at ResolutionRequest.resolveDependency (/Users/dev/Desktop/Sangeeth/mytakeaway2.0/Myt-Mac/MYT_MacOS/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (/Users/dev/Desktop/Sangeeth/mytakeaway2.0/Myt-Mac/MYT_MacOS/node_modules/metro/src/node-haste/DependencyGraph.js:282:16)
    at Object.resolve (/Users/dev/Desktop/Sangeeth/mytakeaway2.0/Myt-Mac/MYT_MacOS/node_modules/metro/src/lib/transformHelpers.js:267:42)
    at dependencies.map.result (/Users/dev/Desktop/Sangeeth/mytakeaway2.0/Myt-Mac/MYT_MacOS/node_modules/metro/src/DeltaBundler/traverseDependencies.js:426:31)
    at Array.map ()
    at resolveDependencies (/Users/dev/Desktop/Sangeeth/mytakeaway2.0/Myt-Mac/MYT_MacOS/node_modules/metro/src/DeltaBundler/traverseDependencies.js:423:18)
    at /Users/dev/Desktop/Sangeeth/mytakeaway2.0/Myt-Mac/MYT_MacOS/node_modules/metro/src/DeltaBundler/traverseDependencies.js:275:33
    at Generator.next ()
    at asyncGeneratorStep (/Users/dev/Desktop/Sangeeth/mytakeaway2.0/Myt-Mac/MYT_MacOS/node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24)
    BUNDLE [macos, dev] ./index.js ░░░░░░░░░░░░░░░░ 3.1% (9/77), failed.
@ghost ghost added the Needs: Triage 🔍 label Aug 28, 2020
@sangeethkumarv
Copy link
Author

I fixed this by removing .ios.js extension with .js in files inside react-native/libraries/components

For example, I changed AccessibilityInfo.ios.js --> AccessibilityInfo.js
Likewise, there are so many files which need these changes like Checkbox, DatePicker, Alert, Settings, etc

@acoates-ms
Copy link
Collaborator

The above error indicates that your metro config is not correct. It should never be loaded files from react-native when bundling for macos -- it should get all the files from react-native-macos.

Are you on 0.62? And using at least version 4.9 of @react-native-community/cli?

@acoates-ms
Copy link
Collaborator

For 0.61 you'd need a seperate metro config for macos, like react-native-netinfo does:
https://github.com/react-native-community/react-native-netinfo/blob/master/metro.config.macos.js

@Abhishek12345679
Copy link

what is causing this issue and how do i fix this ?

@Cedrigax
Copy link

Cedrigax commented Sep 3, 2020

Close running Metro and run react-native run-macos again. It'll solve the problem. No need to change or rename any file

@acoates-ms
Copy link
Collaborator

When bundling for macos, metro should be told to redirect any react-native import to react-native-macos.

In 0.61 you have to do this manually by changing your config when bundling for macos. (The config wont work for other platforms)

  resolver: {
    extraNodeModules: {
      'react-native': path.resolve(__dirname, 'node_modules/react-native-macos')
    },
  },
  serializer: {
    getModulesRunBeforeMainModule: () => [
      require.resolve(
        path.resolve(__dirname, 'node_modules/react-native-macos/Libraries/Core/InitializeCore')),
      ]
  },
  transformer: {
    assetRegistryPath: path.resolve(__dirname, 'node_modules/react-native-macos/Libraries/Image/AssetRegistry'),
  },

For 0.62, so long as you are using @react-native-community/cli@4.9 or greater, then the cli should automatically set this up for you.
See react-native-community/cli#1115 for details of the metro change that allowed this config to happen automatically.

@sidferreira
Copy link

sidferreira commented Sep 10, 2020

I had to remove the global react-native-cli and use npx for everything to have it working properly.

@acoates-ms
Copy link
Collaborator

I was mistaken in my above comment about this happening automatically currently. There was a change that I thought we'd made in react-native-macos that never happened. If I work out what #587 needs, then it would work without a custom metro config. Otherwise, you can run the snipped in my comment above to configure metro correctly for macos.

@sidferreira
Copy link

@acoates-ms Also, it seems that if you run yarn ios first and then yarn macos (or npx), it will fail cause react-native start from iOS won't include MacOS stuff. Now, if you run macos first, it will launch the modified Metro and work properly, including the ios build.

@acoates-ms
Copy link
Collaborator

Can you try this again with react-native-macos 0.62.11.

@Abhishek12345679
Copy link

It works but not with the command from the react-native-docs (npx react-native run-macos)

Instead it works when we start the metro server and app separately as -

  1. yarn start:macos
  2. npx react-native run-macos

@ejlayne
Copy link

ejlayne commented Apr 5, 2021

@acoates-ms @HeyImChris FYI I ran into this again today, where I had run "yarn ios" from fluent-ui-react-native tester app, and then was trying to run "yarn macos" to have both testers up, but ran into this error. I don't know where documentation for react-native-macos is going, but if this issue can't be fixed, then we should mention it as a known issue in documentation (i.e. if you're running both ios and mac, make sure to run macos first). Let me know if you have any questions.

@KyCodes
Copy link

KyCodes commented Jul 3, 2021

I ran into this again today, was able to get past the error with the code above, but am now getting a "No bundle URL present" error. Any ideas?

@thertzelle
Copy link

I'm getting the same error from a clean install of everything:

error: Error: Unable to resolve module ./Libraries/Components/AccessibilityInfo/AccessibilityInfo from /Users/thertzelle/Local_Development/JQuakeMobile/node_modules/react-native/index.js: 

None of these files exist:
  * node_modules/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo(.native|.macos.js|.native.js|.js|.macos.json|.native.json|.json|.macos.ts|.native.ts|.ts|.macos.tsx|.native.tsx|.tsx)
  * node_modules/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo/index(.native|.macos.js|.native.js|.js|.macos.json|.native.json|.json|.macos.ts|.native.ts|.ts|.macos.tsx|.native.tsx|.tsx)

@thertzelle
Copy link

I re-installed my entire environment again, and followed setting up react native and then setting up react native macos, and this is the error I get.

@sungsong88
Copy link

Same here. I'm using an M1 MacBook air and same issue. I tried everything mentioned above.

@github-actions
Copy link

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Sep 14, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

@duasfh
Copy link

duasfh commented Nov 10, 2022

Was anyone with Mac M1 were able to fix this?
Im building pure project without troubles, but this starting to happen for existing project with real dependencies and rn v 0.69.5 .
Configuring metro seems not doing anything; and when trying to comment-out imports from react-native's index.js, it causes error, when it trying to import something from Platform.

@Bojianye
Copy link

Any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests