react-native Metro 捆绑器错误:捆绑失败:ReferenceError:文件的 SHA-1

Posted

技术标签:

【中文标题】react-native Metro 捆绑器错误:捆绑失败:ReferenceError:文件的 SHA-1【英文标题】:react-native metro bundler error: bundling failed: ReferenceError: SHA-1 for file 【发布时间】:2020-03-14 11:46:27 【问题描述】:

我在使用react-native start 时遇到错误,捆绑程序错误是:

bundling failed: ReferenceError: SHA-1 for file /home/suvodip/.nvm/versions/node/v8.17.0/lib/node_modules/react-native/node_modules/metro/src/lib/polyfills/require.js (/home/suvodip/.nvm/versions/node/v8.17.0/lib/node_modules/react-native/node_modules/metro/src/lib/polyfills/require.js) is not computed
    at DependencyGraph.getSha1 (/home/suvodip/.nvm/versions/node/v8.17.0/lib/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph.js:258:13)
    at /home/suvodip/.nvm/versions/node/v8.17.0/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/Transformer.js:211:26
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/home/suvodip/.nvm/versions/node/v8.17.0/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/Transformer.js:46:24)
    at _next (/home/suvodip/.nvm/versions/node/v8.17.0/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/Transformer.js:66:9)
    at /home/suvodip/.nvm/versions/node/v8.17.0/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/Transformer.js:71:7
    at new Promise (<anonymous>)
    at /home/suvodip/.nvm/versions/node/v8.17.0/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/Transformer.js:63:12
    at Transformer.transformFile (/home/suvodip/.nvm/versions/node/v8.17.0/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/Transformer.js:236:7)

自从我安装了react-native-camera 后,我就遇到了这个错误,我不知道这是否是真正的问题。我试过做rm -rf node_modules/ &amp;&amp; yarn install &amp;&amp; react-native start -- --reset-cache,但没用。这是我的***build.gradle 文件:

buildscript 
    ext 
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
    
    repositories 
        google()
        jcenter()
    
    dependencies 
        classpath("com.android.tools.build:gradle:3.4.2")
        classpath("com.google.gms:google-services:4.0.2")
    


allprojects 
    repositories 
 ....

        google()
        jcenter()
        maven  url "https://maven.google.com" 
        maven  url "https://www.jitpack.io" 
    


这是我的app level build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

....
dependencies 
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation "com.google.firebase:firebase-analytics:17.2.2"  // Firebase analytics
    implementation 'com.google.firebase:firebase-core:17.0.0'
    .....


apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply plugin: "com.google.gms.google-services"

【问题讨论】:

【参考方案1】:

npm uninstall react-native-cli &amp;&amp; yarn add global react-native-cli解决的问题,我删除了所有node_modules并重新安装rm -rf node_modules &amp;&amp; yarn install,然后它工作了。

【讨论】:

非常感谢。在 MacOS Catalina 环境 - Android 平台上工作就像一个魅力。

以上是关于react-native Metro 捆绑器错误:捆绑失败:ReferenceError:文件的 SHA-1的主要内容,如果未能解决你的问题,请参考以下文章

react-native 捆绑失败:错误:找不到模块 /metro-react-native-babel-transformer/src/index.js

如何以编程方式启动/停止 Metro Bundler

错误:捆绑失败:错误:找不到相对于目录“C:\\Users\\...”的预设“module:metro-react-native-babel-preset”

console.log 不适用于 react-native

在 react-native 项目中找不到 metro-config node_modules

当我运行“npx react-native start”时找不到模块“@expo/metro-config”