34

I am facing this error while creating bundle of react-native app.

I am executing command react-native bundle --dev false --entry-file index.js --bundle-output ios/main.jsbundle --platform ios

error SHA-1 for file /usr/local/lib/node_modules/react-native/node_modules/metro/src/lib/polyfills/require.js (/usr/local/lib/node_modules/react-native/node_modules/metro/src/lib/polyfills/require.js) is not computed. Run CLI with --verbose flag for more details.
ReferenceError: SHA-1 for file /usr/local/lib/node_modules/react-native/node_modules/metro/src/lib/polyfills/require.js (/usr/local/lib/node_modules/react-native/node_modules/metro/src/lib/polyfills/require.js) is not computed
    at DependencyGraph.getSha1 (/usr/local/lib/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph.js:258:13)
    at /usr/local/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/Transformer.js:211:26
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/usr/local/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/Transformer.js:46:24)
    at _next (/usr/local/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/Transformer.js:66:9)
    at /usr/local/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/Transformer.js:71:7
    at new Promise (<anonymous>)
    at /usr/local/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/Transformer.js:63:12
    at Transformer.transformFile (/usr/local/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/Transformer.js:236:7)
    at /usr/local/lib/node_modules/react-native/node_modules/metro/src/Bundler.js:87:34

react-native info command output

info Fetching system and libraries information...
System:
    OS: macOS Mojave 10.14.3
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 1.73 GB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.16.0 - /usr/local/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
    Android SDK:
      API Levels: 23, 25, 26, 27, 28, 29
      Build Tools: 27.0.3, 28.0.3
      System Images: android-29 | Google Play Intel x86 Atom
      Android NDK: 20.1.5948944
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5522156
    Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.5 => 0.61.5 
  npmGlobalPackages:
    create-react-native-app: 2.0.2
    react-native-cli: 2.0.1
    react-native: 0.61.5
Punita
  • 1,338
  • 2
  • 13
  • 21

13 Answers13

72

To solve my issue I have run command with --force option.

npm install -i -g --force react-native-cli

This issue was raise due to configure old project with old react-native version. and then trying to run latest react-native ver with new Project.

Punita
  • 1,338
  • 2
  • 13
  • 21
16

install with npx run on windows 10

npx react-native run-android

on linux

npx react-native start 
Iman Roosta
  • 2,228
  • 12
  • 13
  • 1
    no, using this command we cannot update/install react-native-cli, issue is with react-native-cli and not react-native library. – Punita Jun 25 '20 at 09:59
13

I resolved the issue in my Mac using

npx react-native start
naheed.shamim
  • 340
  • 2
  • 11
8

For me, I installed the wrong package.

Instead of this:

npm i -g react-native

Make sure you do this:

npm i -g react-native-cli
David Callanan
  • 5,601
  • 7
  • 63
  • 105
4

I can't comment so use npm install -i -g --force react-native-cli as stated by Punita. It works when it comes to fixing the SHA-1 issue.

But please don't use sudo for any npm related things. thanks.

tststs
  • 61
  • 1
1

I think that's about version of react-native-cli.

You should try to update.

npm i -g react-native-cli
Kubilay Kiymaci
  • 472
  • 3
  • 14
  • 2
    I have tried but not work. I have also tried to uninstall react-native and again install but that also not work. – Punita Jan 28 '20 at 04:22
1

To solve my issue I have run command with --force option.

npm install -i -g --force react-native-cli

1

I would like to add that this same error happened to me (running on PC, Windows) when I tried to run the gradle command to build an Android release (./gradlew bundleRelease).

I found the cause of the issue was due to using Dropbox to sync the folder that this React Native project belonged to, using the Dropbox "Back up your PC automatically" feature, where I had my user Documents folder backed up by Dropbox. Essentially, I would get an error like this:

error SHA-1 for file C:\Users\Ted Zhu\Documents\my-app\MyAppWin\index.js (C:\Users\Ted Zhu\Dropbox\PC\Documents\my-app\MyAppWin\index.js) is not computed. Run CLI with --verbose flag for more details. ReferenceError: SHA-1 for file C:\Users\Ted Zhu\Documents\my-app\MyAppWin\index.js (C:\Users\Ted Zhu\Dropbox\PC\Documents\my-app\MyAppWin\index.js) is not computed

I would notice in the error message, it referred to the same file (index.js) with two different paths:

  • C:\Users\Ted Zhu\Documents\my-app\MyAppWin\index.js
  • C:\Users\Ted Zhu\Dropbox\PC\Documents\my-app\MyAppWin\index.js

This must've been because Dropbox created a symbolic link of the folder so that it would have a path within my Dropbox folder. This appears to cause the file in question to have two paths that refer to the same folder, and trick the Metro bundler into thinking that a SHA hash was not created for one of the project files.

The solution was to move this project to a different directory that is not backed up by Dropbox. In my case, I just created a new folder in my user home directory. Then I was able to successfully run the gradle command to build the Android app.

tedz2usa
  • 76
  • 3
  • 1
    OH MY GOODNESS! Thank you. I had tried everything over and over. I was using some symlink folders for convenience and that was the problem. Removed those and it finally worked! – Tanner Lindsay Jan 18 '23 at 22:26
  • Of course @TannerLindsay! Looks like the Metro bundler needs to be improved so that it can support symlinks! – tedz2usa Jan 19 '23 at 02:21
1

For me, global cli update does not work.

enter image description here

I Just run the command like yarn react-native bundle...It works!

yarn react-native bundle --reset-cache --entry-file index.js --platform ios --bundle-output test.bundle --dev false

tangkunyin
  • 1,383
  • 1
  • 8
  • 9
1

To solve I have run

npm install -i -g --force react-native-cli
James Risner
  • 5,451
  • 11
  • 25
  • 47
0

For me, I fixed it by install correct react-native-cli:

yarn global remove react-native-cli
yarn global add react-native-cli
Nishant Patel
  • 1,334
  • 14
  • 22
0

This worked for me:

npx react-native start

When Metro has started, open another Tab on the terminal, same directory then run:

npx react-native bundle ...

The problem for me was not using npx for the react-native command.

Holyfield
  • 31
  • 4
0

In my case, the problem occurred because I was using a node version different from the node version at the time of project setting. Changing the node version solved the problem.

nvm use 16
Woosung Kim
  • 81
  • 1
  • 1
  • 8
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 08 '23 at 16:24