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

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

Open
vjpr opened this issue Dec 11, 2018 · 78 comments
Open

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

vjpr opened this issue Dec 11, 2018 · 78 comments

Comments

@vjpr
Copy link

vjpr commented Dec 11, 2018

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

@Stephen2
Copy link

I got this when trying to get Expo to work with yarn workspaces, using expo-yarn-workspaces

@pavermakov
Copy link

I've got the same issue when I tried to upgrade react-native to 0.57.0. I followed the steps mentioned the change log (https://github.com/react-native-community/react-native-releases/blob/master/CHANGELOG.md#057), but had no luck.

@mareksuscak
Copy link

@Stephen2 me too, did you solve it?

@Stephen2
Copy link

Sorry, moved to different project

@ekmobile
Copy link

ekmobile commented Mar 29, 2019

This is still a problem today with "react-native": "^0.59.2". Will there be real fix or do we need to copy/paste the workaround?

  • BUNDLE_FILE=/Users/.../Library/Developer/Xcode/DerivedData/...-aexneivqfarcnddyzdbcbwoienmj/Build/Products/Release-iphoneos/....app/main.jsbundle
  • node /Users/.../git/...-app-react-native/.../node_modules/react-native/cli.js bundle --entry-file index.js --platform ios --dev false --reset-cache --bundle-output /Users/.../Library/Developer/Xcode/DerivedData/...-aexneivqfarcnddyzdbcbwoienmj/Build/Products/Release-iphoneos/....app/main.jsbundle --assets-dest /Users/.../Library/Developer/Xcode/DerivedData/...-aexneivqfarcnddyzdbcbwoienmj/Build/Products/Release-iphoneos/....app
    warning: the transform cache was reset.
    Loading dependency graph, done.
    error SHA-1 for file /Users/.../git/...-app-react-native/.../node_modules/metro/src/lib/polyfills/require.js (/Users/.../git/...-app-react-native/.../node_modules/metro/src/lib/polyfills/require.js) is not computed
  • [[ false != true ]]
  • [[ ! -f /Users/.../Library/Developer/Xcode/DerivedData/...-aexneivqfarcnddyzdbcbwoienmj/Build/Products/Release-iphoneos/....app/main.jsbundle ]]
  • echo 'error: File /Users/.../Library/Developer/Xcode/DerivedData/...-aexneivqfarcnddyzdbcbwoienmj/Build/Products/Release-iphoneos/....app/main.jsbundle does not exist. This must be a bug with'
    error: File /Users/.../Library/Developer/Xcode/DerivedData/...-aexneivqfarcnddyzdbcbwoienmj/Build/Products/Release-iphoneos/....app/main.jsbundle does not exist. This must be a bug with
  • echo 'React Native, please report it here: https://github.com/facebook/react-native/issues'
    React Native, please report it here: https://github.com/facebook/react-native/issues
  • exit 2

@nick-michael
Copy link

For anyone seeing this error when using expo-yarn-workspaces, I got this and fixed it by simply deleting the auto-generated file (the file that the error points to) and deleting all the node modules and then just running yarn again to re-install node modules and re-generate the file.

@ghost
Copy link

ghost commented Oct 30, 2019

I am experiencing this on RN 0.60.5

@dioptre
Copy link

dioptre commented Oct 30, 2019

Also fixes RN 0.61

@ghost
Copy link

ghost commented Oct 31, 2019

Also fixes RN 0.61

Do you mean that on RN 0.61 it is working as expected?

@donholly
Copy link

donholly commented Nov 4, 2019

Seeing the same issue as described on 0.60.5. The workaround provided by @vjpr works - thank you! Looks like #455 should fix this. I'm curious why doesn't seem to be a bigger problem for everyone 😄

I made the change in ~/.config/yarn/global/node_modules/metro/src/node-haste/DependencyGraph.js

@dioptre
Copy link

dioptre commented Nov 5, 2019

@dusan-dragon I needed the @vjpr fix to get RN 0.61 to work.

@ricick
Copy link

ricick commented Nov 28, 2019

I'm having this issue on a windows 10 machine here. Same project on another dev machine with the same version of node doesn't display the issue.

@ikbal99
Copy link

ikbal99 commented Dec 11, 2019

put all files inside assets name of folder something like this

../../assets/beach.jpg

@vj-raghavan
Copy link

@donholly I am not sure why no one is flagging this issue more. I have just run in to this issue after I have setup a new terminal and cleaned up all my old node modules.

Thanks to @vjpr workaround it worked after rebuilding the app. Is this a miss on our part ? or is this being actively looked into ?

@mhers91
Copy link

mhers91 commented Dec 15, 2019

put all files inside assets name of folder something like this

../../assets/beach.jpg

This worked for me ikbal99

@Gerlison
Copy link

Works for me, 0.61.5

@nkraev
Copy link

nkraev commented Dec 25, 2019

0.61.5 indeed works.
I also did npm i -g react-native-cli - it updated cli to 2.0.1 version and bundling worked.

@bkhurjawal
Copy link

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.

@ricick
Copy link

ricick commented Jan 7, 2020

I found it was an issue with me accessing the project on a second drive via a symlink on C: rather than navigating to the D: drive

@f4th4n
Copy link

f4th4n commented Jan 10, 2020

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

yarn global remove react-native
yarn global add react-native-cli

@martinfrouin
Copy link

Thanks @f4th4n it works for me

@finghtingjie
Copy link

finghtingjie commented Jan 17, 2020

I had tried all the methods above but still not work for me.
OS:mac Catalina
node:13.3.0
watchman:4.9.0
react-native:0.61.5

the error log like this

Metro Bundler has encountered an error: SHA-1 for file /Users/.../Downloads/AwesomeProject/node_modules/metro/src/lib/polyfills/require.js (/Users/.../Downloads/AwesomeProject/node_modules/metro/src/lib/polyfills/require.js) is not computed

@MohamedHamedLab
Copy link

i had the same issue and fix it by following this steps
1- updating metro-react-native-babel-preset to version 0.57.0
2- resetCache: true in metro.config
3- removeing node modules & yarn lock file and reinstall

@isameera
Copy link

just use npx
Ex: npx react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res

@DouglasAzevedo
Copy link

A solução proposta por @vjpr funcionou perfeitamente pra mim.

@rpcarnell
Copy link

The solution offered by @vjpr worked like a charm.

@khomchyk
Copy link

Hello!
Are there any plans to fix this issue or support searching for symlinks?

The patch suggested by @vjpr is working, but it will be better to have an official support of this functionality.

@agelessZeal
Copy link

npm i -g react-native-cli
It is solution of this issue.

crutchcorn added a commit to oceanbit/GitShark that referenced this issue Jan 31, 2021
In this commit I wanted to use `require` to import the `.github/ISSUE_TEMPLATE` in order to include
the file contents.

However, despite doing a lot of research and trying my best to figure out the METRO bundler, I
cannot seem to get this working as-expected. I keep getting a "SHA-1 for file is not computed"
error. According to this thread:

facebook/metro#330

One potential solution is to patch metro in order to generate the SHA. However, I don't want to
patch metro, that admittedly feels a bit flaky as a solution.

In the next commit we'll revert the metro changes and use the GH API to get the bug report file
contents instead
crutchcorn added a commit to oceanbit/GitShark that referenced this issue Jan 31, 2021
In this commit I wanted to use `require` to import the `.github/ISSUE_TEMPLATE` in order to include
the file contents.

However, despite doing a lot of research and trying my best to figure out the METRO bundler, I
cannot seem to get this working as-expected. I keep getting a "SHA-1 for file is not computed"
error. According to this thread:

facebook/metro#330

One potential solution is to patch metro in order to generate the SHA. However, I don't want to
patch metro, that admittedly feels a bit flaky as a solution.

In the next commit we'll revert the metro changes and use the GH API to get the bug report file
contents instead
@rad182
Copy link

rad182 commented Feb 13, 2021

If anyone else having issue when archiving ios.
I had to install react-native-cli and use it.
yarn add react-native-cli
then override CLI_PATH
image

@huzaifaaak
Copy link

I am getting this issue on rn-tester app on android. None of the above is working for me

@JulesGuesnon
Copy link

Hi there !

My case is probably unlikely: the folder containing the project had .zip in the name and was causing the issue.

I checked the code and there's a specific case for .zip files in getSha1 which caused the error

@vjpr
Copy link
Author

vjpr commented Sep 1, 2021

If you are using pnpm, see pnpm/pnpm#3731.

@zaidraddad94
Copy link

you ar the man

@muganwas
Copy link

put all files inside assets name of folder something like this

../../assets/beach.jpg

This worked for me, thanks!

@FoolCoder
Copy link

i am having this issue while generating debug apk! why?

@patricksantos-bcs
Copy link

patricksantos-bcs commented Dec 28, 2021

If anyone else having issue when archiving ios. I had to install react-native-cli and use it. yarn add react-native-cli then override CLI_PATH image

This one works for me! Thanks!

@Vednus
Copy link

Vednus commented Jan 17, 2022

Just an FYI: was having this issue when running codepush and fixed it by restarting my machine.

@instanceof-inf
Copy link

None of the above worked for me, the only thing that worked was checking the 'For install builds only' checkbox under 'Bundle React Native code and images' under Build Phases
Screenshot 2022-11-22 at 22 21 36

budiadiono added a commit to budiadiono/metro that referenced this issue Dec 25, 2022
@fwielstra
Copy link

Just an addition, I ran into this issue today; at first I thought it was due to having pages and routers of my app spread across different libraries using NX, which uses a symlink to node_modules in every app project.

However, the issue was that I already had Metro running in another terminal tab, and kept trying to remove node_modules and restart the app (and Metro) in another tab.

TL;DR make sure there are no other Metro processes running when you try anything described in this thread.

@kennethkeim
Copy link

kennethkeim commented Feb 7, 2023

Just an FYI: was having this issue when running codepush and fixed it by restarting my machine.

Machine restart fixed my issues too.

TL;DR make sure there are no other Metro processes running when you try anything described in this thread.

It may be that I had a metro process running in the background that got disconnected from my terminal emulator.

@dezoxel
Copy link

dezoxel commented Feb 9, 2023

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.

I have the same issue.
React Native v0.71.2.

Running thru yarn start solves the issue, thanks a lot!

@lukasgjetting
Copy link

lukasgjetting commented May 16, 2023

Started working again after I ran watchman watch-del '{PROJECT_DIR}' where {PROJECT_DIR} is the root directory of your RN project, i.e. /Users/lukas/projects/myapp

@yoannes
Copy link

yoannes commented Aug 5, 2023

RN 0.72.3

I'm using yarn workspaces and the following worked for me:

  "workspaces": {
    "packages": [
      "packages/*"
    ],
    "nohoist": [
      "**/react-native",
      "**/react-native/**",
      "**/@react-native",
      "**/@react-native/**"
    ]
  },

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

No branches or pull requests