react-native metro bundler error: bundling failed: ReferenceError: SHA-1 for file

烈酒焚心 提交于 2021-01-29 12:58:32

问题


I am getting the an error when I am using react-native start, the bundler error is:

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)

I am getting this error ever since I have installed the react-native-camera, I don't know if that is the real issue. I have tried doing rm -rf node_modules/ && yarn install && react-native start -- --reset-cache but it didn't work. Here is my top level build.gradle file :

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" }
    }
}

Here is my 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:


The problem solved by npm uninstall react-native-cli && yarn add global react-native-cli and I removed all node_modules and reinstalled with rm -rf node_modules && yarn install, then it worked.



来源:https://stackoverflow.com/questions/60682365/react-native-metro-bundler-error-bundling-failed-referenceerror-sha-1-for-fil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!