问题
I work on an App in React-Native / Expo and I can't install firebase.
I create a new Projet in Expo : "test2". (No problem)
I run "npm install --save firebase" in cmd and i got this :
C:\Users\Nils\test>npm install --save firebase
node-pre-gyp install --fallback-to-build --library=static_library
node-pre-gyp WARN Using request for node-pre-gyp https download
Success: "C:\Users\Nils\test\node_modules\grpc\src\node\extension_binary\ node-v57-win32-x64-unknown\grpc_node.node" is installed via remote
npm notice created a lockfile as package-lock.json. You should commit this file.
+ firebase@5.4.2
added 179 packages from 71 contributors, removed 369 packages, updated 643 packages and audited 20975 packages in 440.187s
found 0 vulnerabilities**
- Expo tell me that I don't have React-Native and that I should use "npm install" (That's strange the new project worked well 5 minutes ago, before firebase.) :
Error: React native is not installed. Please run npm install in your project directory.
- I run "npm install" in cmd :
C:\Users\Nils\test>npm install
added 260 packages from 160 contributors, updated 4 packages and audited 30579 packages in 121.866s
found 2 vulnerabilities (1 low, 1 high) run `npm audit fix` to fix them, or `npm audit` for details**
5 I run my App in Expo and I got : Can't find variable : Self
I don't understand why it doesn't work, I don't even know where the problem is comming from ...
回答1:
For users creating new project with expo-cli or XDE, you will get red screen “Can’t Find Variable Self” after your first “yarn” or “npm install”. This is because of new “whatwg-fetch” 3.0.0 published yesterday (https://www.npmjs.com/package/whatwg-fetch 23).
So you just need to force dependency to previous version:
"whatwg-fetch": "^2.0.4"
It means put it in package.json as “dependency”. Manually, with “yarn add whatwg-fetch@2.0.4.” Or with “npm add whatwg-fetch@2.0.4”.
Everything should now work like a charm.
Hope this helps ;p
Links:
React Native Expo Can't Find Variable Self
https://forums.expo.io/t/cant-find-variable-self/13547
回答2:
These are the steps of how I create a react-native project and integrate Firebase.
Step 1 :- Create React-Native project
run react-native init <PROJECT NAME> --version="0.55.2". After project creation, go inside the project folder by cd <Project Name> and follow the below steps.
Step 2 :- Install React-Native Firebase from NPM
run npm install --save react-native-firebase
Step 3 :- Link React-Native Firebase
run react-native link react-native-firebase
Step 4 (Optional/Suggested Method) :- Connect to Firebase using Android Studio
1) Open android folder in your React-Native project using Android Studio.
2) Android Studio will suggest you a bunch of Gradle updates which you have to do, if it is not asking Gradle Updates Rebuild Project (Build->Rebuild Project) and check.
3) Clear warnings in build.gradle scripts (most of them would be replacement of Compile to Implementation in dependencies which Android Studio would suggest).
4) Next go to Tools->Firebase(Remember you have to be signed in using your gmail account in Android Studio, you can do that by going to the top right corner profile image option). Firebase Assistant will open, Click any option, thereby you will get a option saying Connect to Firebase, Click it and create you own Firebase Project and thereby connect to Firebase.
5) Thereby you have successfully Connected to Firebase in your android project.
Step 4 (Faster Method) :- Connect to Firebase
1) Create Firebase Project. Refer this Link
2) Platform Specific Installation. Refer this Link (Remember when you are Adding Firebase to your Project, I suggest you to fill the credentials which are optional correctly)
3) Follow the Instructions under whichever platform you are working on.
I request you to refer RNfirebase for detailed documentation.
I hope I could help you.
来源:https://stackoverflow.com/questions/52262184/cant-find-variable-self-cant-install-firebase