question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`SHA-1 for file ... is not computed` when using `resolver.resolveRequest`

See original GitHub issue

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

I am using a custom resolver.resolveRequest function in rn-cli.config.js. See https://facebook.github.io/metro/docs/en/configuration#resolver-options.

The error message is being printed from metro/src/node-haste/DependencyGraph.js#getSha1, which is being called by metro/src/Bundler.js#transformFile:

metro/src/node-haste/DependencyGraph.js#getSha1

  getSha1(filename: string): string {
    const resolvedPath = fs.realpathSync(filename);
    const sha1 = this._hasteFS.getSha1(resolvedPath);
    if (!sha1) {
      throw new ReferenceError(`SHA-1 for file ${filename} is not computed`);
    }
    return sha1;
  }

The issue is that the file won’t exist in the haste map if you are resolving it in the resolveRequest hook.

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.

https://github.com/vjpr/expo-v2-test-pnpm/tree/broken

You need to run pnpm install (the reason for the custom resolver is because symlinks are not supported by metro and hence cause problems for pnpm).

What is the expected behavior?

getSha1 should compute hash if not in haste map.

Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.

metro@0.45.6 node@8.9.0 pnpm@2.21.1

Workaround

Add to metro/src/node-haste/DependencyGraph.js#getSha1:

    if (!sha1) {
      return getFileHash(resolvedPath)
      function getFileHash(file) {
        return require('crypto')
          .createHash('sha1')
          .update(fs.readFileSync(file))
          .digest('hex')
      }
    }

I have released a patched version here: Use metro-pnpm@0.45.6-vjpr.2

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:106
  • Comments:73

github_iconTop GitHub Comments

114reactions
bkhurjawalcommented, Jan 7, 2020

I solved this issue by using yarn start instead of starting project with react-native start(it uses npm start). I have been adding dependencies in project using Yarn add {dependencyName} and starting project via npm. which created error of SHA-1.

86reactions
f4th4ncommented, Jan 10, 2020

I fixed it by install correct react-native-cli:

yarn global remove react-native
yarn global add react-native-cli
Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - `SHA-1 for file ... is not computed` when using ...
What is the current behavior? I am using a custom resolver.resolveRequest function in rn-cli.config.js . See https://facebook.github.io/metro/ ...
Read more >
React-Native Bundle Error error SHA-1 for file is not computed
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...
Read more >
Referenceerror: Sha-1 For File Is Not Computed - ADocLib
SHA1 for file is not computed when using resolver. I have platformdependent pictures with.android.png |.ios.png extension in my I decided to upgrade to...
Read more >
React-Native Bundle Error error SHA-1 for file is not computed
iOS : React-Native Bundle Error error SHA-1 for file is not computed [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] ...
Read more >
HTTP-Artifacts binding SAML Request to IdP - ComponentSpace
So while sending request using below code ComponentSpace not putting ... It's where you send the artifact resolve request over SOAP.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found