`SHA-1 for file ... is not computed` when using `resolver.resolveRequest`
See original GitHub issueDo 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:
- Created 5 years ago
- Reactions:106
- Comments:73
Top GitHub Comments
I solved this issue by using
yarn start
instead of starting project withreact-native start
(it uses npm start). I have been adding dependencies in project usingYarn add {dependencyName}
and starting project via npm. which created error of SHA-1.I fixed it by install correct
react-native-cli
: