React-native install issue in expo app - react-native

I'm trying to learn react-native by creating an app using the expo development environment. I had a working app (little more than the code that shipped with expo) until installing redux. Currently I am getting the following error from the XDE:
Problem checking node_modules dependencies: Unexpected end of JSON input
and the following from the ios simulator:
undefined is not an object (evaluating 'ReactPropTypes.string')
Package.json:
{
"name": "myApp",
"version": "0.0.0",
"description": "Hello Expo!",
"author": null,
"main": "main.js",
"scripts": {
"test": "node node_modules/jest/bin/jest.js"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"#expo/ex-navigation": "~3.0.0",
"#expo/samples": "~1.0.3",
"babel-preset-react": "^6.24.1",
"expo": "17.0.0",
"react": "^16.0.0-alpha.12",
"react-native": "^0.45.1",
"react-redux": "^5.0.5",
"redux": "^3.6.0"
},
"devDependencies": {
"jest-expo": "~1.0.1"
}
}
I believe my node modules contain valid JSON. It should be noted that I'm using a more current version of react-native than expo. Is this an issue with the packages I have installed? Which files would be helpful in solving this?

Although I haven't been able to fix this particular error. This one and many others can be avoided by using yarn instead of npm when working with expo (I have no affiliation with either tool).

I believe this is due to a bug in the current release of npm 5. As mentioned in the other answer here, using npm 4 or yarn will resolve this problem.

Related

All my react-native projects shows error TypeError: cb.apply is not a function

I'm realtively new to react-native. All my projects were running fine in the morning, but somehow they stopped working. When I run react-native start and the react-native run-android, the app gets installed on the device but then this error props up which was not happening before.
Loading dependency graph, done.
DELTA [android, dev] ./index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1)/home/yehyaumar/Documents/dumm/busybee/node_modules/graceful-fs/polyfills.js:285
if (cb) cb.apply(this, arguments)
^
TypeError: cb.apply is not a function
at /home/yehyaumar/Documents/dumm/busybee/node_modules/graceful-fs/polyfills.js:285:20
at FSReqCallback.oncomplete (fs.js:169:5)
I even cloned the repo from from scratch, but still the error persists. Please help out.
RN version: 0.59.2
My package.json file for one project,
{
"name": "projectalpha",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#react-native-community/async-storage": "^1.11.0",
"axios": "^0.18.0",
"react": "16.8.3",
"react-native": "0.59.2",
"react-native-awesome-alerts": "^1.2.0",
"react-native-circle-checkbox": "^0.1.6",
"react-native-circular-progress": "^1.1.0",
"react-native-gesture-handler": "^1.1.0",
"react-native-google-places-autocomplete": "^1.3.9",
"react-native-image-picker": "^0.28.1",
"react-native-maps": "react-native-community/react-native-maps#master",
"react-native-maps-directions": "^1.6.0",
"react-native-onesignal": "^3.2.12",
"react-native-reanimated": "^1.0.0-alpha.12",
"react-native-svg": "^9.4.0",
"react-native-svg-charts": "^5.2.0",
"react-native-swiper": "^1.5.14",
"react-native-tab-view": "^2.0.3",
"react-native-vector-icons": "^6.4.2",
"react-navigation": "^3.6.0",
"unstated": "^2.1.1"
},
"devDependencies": {
"#babel/core": "^7.4.0",
"#babel/runtime": "^7.4.2",
"#react-native-community/eslint-config": "^0.0.3",
"babel-jest": "^24.5.0",
"eslint": "^5.15.3",
"jest": "^24.5.0",
"metro-react-native-babel-preset": "^0.53.1",
"react-test-renderer": "16.8.3"
},
"jest": {
"preset": "react-native"
},
"rnpm": {
"assets": [
"./assets/fonts/"
]
}
}
Ciao, this problem is connected to graceful-fs package. Plase, reinstall graceful-fs:
npm install graceful-fs --save-dev
And problem should be solved.
For me, npm cache clean —force was not working, and graceful-fs is not direct dependency in my project.
OS: Ubuntu
Node: 14.6.0
Npm: 6.14.7
I am still not sure why this error exits, but it works. I found this solution on Flavio Copes's post.
open file /node_modules/graceful-fs/polyfills.js, where the error comes from.
Here’s the function that gives the problem:
function statFix (orig) {
if (!orig) return orig
// Older versions of Node erroneously returned signed integers for
// uid + gid.
return function (target, cb) {
return orig.call(fs, target, function (er, stats) {
if (!stats) return cb.apply(this, arguments)
if (stats.uid < 0) stats.uid += 0x100000000
if (stats.gid < 0) stats.gid += 0x100000000
if (cb) cb.apply(this, arguments)
})
}
}
comment out these lines (line 62-64):
// fs.stat = statFix(fs.stat)
// fs.fstat = statFix(fs.fstat)
// fs.lstat = statFix(fs.lstat)
I've run into this problem while trying to start a react-native development server on one of my old projects - (React Native version 0.59.x). For me, the fix was downgrading the node version from 14 to 10 using nvm
Go to C:\Users(your username)\AppData\Roaming
Delete npm and npm-cache
Try running again if it gives the error again uninstall and delete Nodejs completely, check that those two files above are still nonexistent and then redownload Nodejs.
On one of my computers the first way worked no problems the second one needed to have Nodejs completely replaced and then worked.
here is the solution for it.
Option 1:
Follow this directory
C:\Users(your username)\AppData\Roaming
Delete the npm folder and if there is one mom cache folder.
Run npm clean cache —force ( — force is now required to clean cache)
You should be good now if not do option 2.
Option 2:
Follow this directory
C:\Users(your username)\AppData\Roaming
Delete the npm folder and if there is one mom cache folder.
Run npm clean cache —force ( — force is now required to clean cache)
Make sure everything to do with Nodejs is deleted and uninstalled.
Reinstall Nodejs.
You should be good now
I had to use node 12.3.1 and npm 6.9.0 to fix this error
nvm use 12.3.1
This installed both. npm install working again.

Google Cloud Function: Dependency not found

I am developing a project on Nuxt that I am deploying as a Google Cloud Function. (I Chose this as I am using a Cloud Firestore for my data storage)
It all works very nicely so far (Except the cold start time is persistently high - about 6 seconds but I think that is a separate matter). However, I keep getting this WARN in the logs on my Cloud Function:
textPayload: " WARN The dependency eslint not found. Please run yarn add eslint --dev or npm install eslint --save-dev"
There is nothing in the error to suggest where it is requiring eslint or why. This does not happen when I run my code or deploy locally.
My package.json looks like this:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "nuxt start",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "10"
},
"dependencies": {
"#nuxtjs/axios": "^5.9.7",
"#nuxtjs/eslint-config": "^2.0.0",
"#nuxtjs/eslint-module": "^1.1.0",
"#nuxtjs/vuetify": "^1.10.3",
"cookieparser": "^0.1.0",
"firebase": "^7.13.2",
"firebase-admin": "^8.6.0",
"firebase-functions": "^3.3.0",
"js-cookie": "^2.2.1",
"jwt-decode": "^2.2.0",
"nuxt": "^2.12.2",
"nuxt-client-init-module": "^0.1.8",
"nuxt-start": "^2.11.0",
"vuetify": "^1.0.0",
"selectiveSSR": "file:./local-modules/selective-ssr",
"shortid": "^2.2.15",
"sortablejs": "^1.10.2",
"vue-moment": "^4.1.0",
"vue-uuid": "^1.1.1",
"vuex-persistedstate": "^3.0.1"
},
"devDependencies": {},
"private": true
}
The Warning suggests it is looking for a dev-dependency. Surely I don't need these in my package.json? (Even if I add it in I still see the warning). There are references to the eslint package in my package-lock.json (which makes sense as I guess the nuxtjs/eslint packages in my package.json need it) but:
The link to the gzipped eslint NPM in package-lock.json works OK when I access it in my browser
Should Google not be using its Package Cache anyway to speed up the cold start? Is the issue that the specific version of eslint package-lock.json refers to is not available in Google's local package cache?
And yes I have tried adding eslint to my dependencies and devDependencies and it makes no difference.

Once i create and use own module then it will gives error like: Unable to resolve module

I am new in react-native and I have, for the first time, created my own module(npm).
I have tried to create my own module(npm) for common components and individually it works fine. However once I install, link it in our app, and try to use those components, it gives an error like this:
Unable to resolve module `<Module-name>` from `<file>`: Module `<Module-name>` does not exist in the Haste module map.
(Note: I have tested using Android Emulator only)
I have followed the below steps for module and test app creation
For Module
react-native init <module-name>
Add simple code of component in main index.js
And set pacakge.json like this:
{
"name": "<module-name>",
"version": "0.0.1",
"private": true,
"main": "index.js",
"scripts": {
"start": "react-native start",
"test": "jest",
"lint": "eslint .",
"build": "echo 'build script executed'"
},
"dependencies": {
"react": "16.8.6",
"react-native": "0.60.4"
},
Now I check this component (react-native run-android), it will work fine.
Now I have tried to use in an app with the below steps
For Test App
Create new fresh app (react-native init <app-name>)
Install created npm with full path like;
npm install <full path of component>
Now I try react-native link <full path of component>, I have also tried simple react-native link, but nothing happens.
Now I run app using react-native run-android, however every time it gives the same error like;
Unable to resolve module <created-module name>
test app package.json
{
"name": "<app-name>",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"react": "16.8.6",
"react-native": "0.60.4",
"react-native-my-library": "^1.0.2",
"<created-module-name>": "file:../<created-module-name>"
},
"devDependencies": {
"#babel/core": "7.5.5",
"#babel/runtime": "7.5.5",
"#react-native-community/eslint-config": "0.0.3",
"babel-jest": "24.8.0",
"eslint": "6.1.0",
"jest": "24.8.0",
"metro-react-native-babel-preset": "0.54.1",
"react-test-renderer": "16.8.6"
},
"jest": {
"preset": "react-native"
}
}
Created module successfully installed but I think it is not linked properly and it will gives error.
So what is wrong here ?
Please give me suggestion / help.
Thanks.
I am assuming your module is successfully published in npm repository. Otherwise you can not use npm install <full path of component>.
If you are using
npm install <full path of component>
command for installing your module to a Test App from npm repo. Specify in your package.json like
"<created-module-name>": "file:../<created-module-name>"
is wrong. You need to remove that line from your package.json and try to install like;
npm install --save <full path of component>
This will automatically create a line in your package.json. You can now manually link your module.
For manual linking you can follow that guide.
Edited:
If you are using in your local computer,
Then no need to npm install.
Just copy your module into your project node_modules folder.
Then in you package.json add;
"dependencies": {
...
"your_module_name": "your_module_version"
...
}
Then, you just follow the manual linking process that I mentioned above.

Unrecognized command 'run-eject'

I want to eject my react-native so I can install mobx but running both 'yarn run eject' and 'npm run eject' doesn't work.i think this is new issue and so couldn't find help online. any help would be appreciated.
this is my package.json file and the error given below.
{
"name": "a2x",
"version": "0.1.0",
"private": true,
"devDependencies": {
"babel-preset-react-native-stage-0": "^1.0.1",
"jest": "^22.4.4",
"jest-react-native": "^18.0.0",
"react-test-renderer": "16.3.1"
},
"scripts": {
"start": "react-native start",
"android": "react-native run-android",
"ios": "react-native run-ios",
"test": "jest",
"eject": "react-native run-eject"
},
"jest": {
"preset": "react-native"
},
"dependencies": {
"axios": "^0.18.0",
"mobx": "^5.5.0",
"mobx-react": "^5.2.8",
"react": "16.3.1",
"react-native": "~0.55.2",
"react-native-elements": "^0.19.1",
"react-navigation": "^2.0.1"
}
}
Try npm run eject..not npm run-eject
But if you trying to add native dependencies later i think better to start project using react native init. not using create-react-native-app.
Actual command is react-native eject.
It will create new folder for android and iOS to run it seperately on native.
As you said you are getting error of Both the iOS and Android folders already exist!, so please delete it and try with this command.
If you already have android and ios folder with some native implementation, there is no need to use eject command at all.
regarding npm run reject command, I guess this will be more useful to clear everything.
Always working for me, only follow two steps
first install in your project
yarn add react-native-eject
and then run
react-native eject
make sure you have install yarn in your pc

unable to resolve module `#expo/vector-icons`

Im not sure why I'm getting this error:
Unable to resolve module `#expo/vector-icons` from `...(directory path here)...` : Module does not exist in the module pack
I have tried the following things suggested on other forums/sites:
Clear watchman watches
Deleting the node_modules folder
Reset packager cache
package.json
{
"name": "app name",
"version": "0.0.0",
"description": "Hello Expo!",
"author": null,
"private": true,
"main": "node_modules/expo/AppEntry.js",
"dependencies": {
"babel-plugin-module-resolver": "^2.5.0",
"babel-preset-expo": "^4.0.0",
"expo": "^21.0.0",
"firebase": "^4.5.1",
"geofire": "^4.1.2",
"moment": "^2.19.1",
"react": "16.0.0-alpha.12",
"react-native": "https://github.com/expo/react-native/archive/sdk-21.0.2.tar.gz",
"react-navigation": "^1.0.0-beta.13"
}
}
But still nothing, still getting this error
I resolved the issue by this command npm install #expo/vector-icons --save
I ran into the same issue. It's the babel-preset-expo. uninstall that and do the following
npm i metro-react-native-babel-preset --save-dev
delete the babel.config.json and create a new file called .babelrc
then specify the preset
{
"presets": ["module:metro-react-native-babel-preset"]
}
Sounds like vector-icons is another library you should be declaring in your package.json (https://www.npmjs.com/package/#expo/vector-icons)
Command npm install #expo/vector-icons --save do the trick !
The reason why I had this error, was because when I put useState in my app, VS Code auto imported it from react-native-vector-icons/node_modules/#types/react, instead of from "react"