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

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.

Related

Laravel's React Breeze ,Always can't run : npm run dev

The Vite doesn't work
Os:CentOs7
Laravel: 9.26.1
node: v16.17.0
npm: 8.15.0
I would like use new Laravel Project with React.js.
And try the plug-in Breeze for Authentication
I use the command
composer create-project laravel/laravel new-project
php artisan breeze:install
php artisan breeze:install react
npm install
npm run dev
At first all command successful complete , but when i use
npm run dev
the server told me
/tmp/dev-xxxxxx.sh: line 1: vite: command not found
and i try the solution
https://github.com/vitejs/vite/discussions/5432
and
https://github.com/vitejs/vite/issues/1215
that's all not work for me
this is package.json
{
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"#headlessui/react": "^1.4.2",
"#inertiajs/inertia": "^0.11.0",
"#inertiajs/inertia-react": "^0.8.0",
"#inertiajs/progress": "^0.2.6",
"#tailwindcss/forms": "^0.5.2",
"#vitejs/plugin-react": "^2.0.0",
"alpinejs": "^3.4.2",
"autoprefixer": "^10.4.2",
"axios": "^0.27",
"laravel-vite-plugin": "^0.5.0",
"lodash": "^4.17.19",
"postcss": "^8.4.6",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"tailwindcss": "^3.1.0"
},
"dependencies": {
"vite": "^3.0.9"
}
}
How should I do to resolve this question?
I find the question
i type before npm install
npm config set bin-links false
because CentOs7 have sym link error(bin-link to my laptop)
that can not install complete
so i should set bin-links to true
and
npm install vite
it's would solve the problem

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.

react-native fails on bundling

I hope you can help me with an issue I encountered today and I am totally lost at the moment. I have a react-native project going and yesterday everything was working just fine, but today I was trying to start up the bundler, simulator and so on, but got a strange error instead that leaves me totally in the wild with no real clue where to get into this.
Error message
error: bundling failed: SyntaxError: Unexpected token, expected { (52:36)
at Parser.pp$5.raise (/Users/michel.engelen/...<patchToProject>.../node_modules/babylon/lib/index.js:4454:13)
at Parser.pp.unexpected (/Users/michel.engelen/...<patchToProject>.../node_modules/babylon/lib/index.js:1761:8)
at Parser.pp.expect (/Users/michel.engelen/...<patchToProject>.../node_modules/babylon/lib/index.js:1749:33)
at Parser.pp$1.parseClassBody (/Users/michel.engelen/...<patchToProject>.../node_modules/babylon/lib/index.js:2436:8)
at Parser.pp$1.parseClass (/Users/michel.engelen/...<patchToProject>.../node_modules/babylon/lib/index.js:2406:8)
at Parser.pp$1.parseStatement (/Users/michel.engelen/...<patchToProject>.../node_modules/babylon/lib/index.js:1843:19)
at Parser.pp$1.parseBlockBody (/Users/michel.engelen/...<patchToProject>.../node_modules/babylon/lib/index.js:2268:21)
at Parser.pp$1.parseTopLevel (/Users/michel.engelen/...<patchToProject>.../node_modules/babylon/lib/index.js:1778:8)
at Parser.parse (/Users/michel.engelen/...<patchToProject>.../node_modules/babylon/lib/index.js:1673:17)
at Object.parse (/Users/michel.engelen/...<patchToProject>.../node_modules/babylon/lib/index.js:7305:37) [/Users/michel.engelen/...<patchToProject>.../node_modules/react-native/Libraries/Components/Button.js]
This message pops up in the terminal when entering npm start -- --reset-cache and react-native run-ios afterwards.
Project settings / packages installed
Here are my dependencies inside the package.json:
"dependencies": {
"npm": "6.3.0",
"prop-types": "15.6.2",
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-fontawesome": "5.7.0",
"react-native-remote-svg": "1.2.0",
"react-native-splash-screen": "3.1.1",
"react-navigation": "2.11.2",
"react-redux": "5.0.7",
"redux": "3.7.2",
"redux-thunk": "2.3.0",
"redux-undo": "1.0.0-beta9-9-7"
},
"devDependencies": {
"#babel/core": "7.0.0-beta.56",
"babel-plugin-add-module-exports": "0.2.1",
"babel-preset-es2015": "6.24.1",
"babel-preset-react-native": "4.0.0",
"eslint": "5.3.0",
"eslint-config-google": "0.9.1",
"eslint-plugin-import": "2.13.0",
"eslint-plugin-jsx-a11y": "6.1.1",
"eslint-plugin-react": "7.10.0",
"eslint-plugin-react-native": "3.2.1",
"redux-devtools-extension": "2.13.5"
},
I did not specify ranges on them because that nearly always resulted in strange errors with other bundling issues (not this time though).
efforts to solve this (`til now)
rm -rf node_modules/ package-lock.json
upgrading the packages
removing jest from the dependencies
rm -rf ios/ android/ && react-native eject
reset the branch to a commit in the past that was working for sure
I even used yarn instead of npm during all of these steps to see if it has any impact on the outcome
I even tried to reboot the MacBook, but nothing worked up until now.
I seriously hope that somebody can help me with this, because otherwise I would probably have to redo everything, which would take me a lot of time.

Cannot Find Module '#babel/core' react-native

Bundling index.js [development, non-minified] 0.0% (0/1), failed.
error: bundling failed: Error: Cannot find module '#babel/core' (While processing preset:
Others have had similar problems which were solved by one of the following:
Uninstalling babel-preset-react-native and installing it again #2.1.0.
Some people could only fix this using yarn and not npm
Moving Babel to devDependancies
Updating the .babelrc file with
{
"presets": [
"react-native"
],
"env": {
"development": {
"plugins": [
"transform-react-jsx-source"
]
}
}
}
Unfortunately, not a single one of these worked for me. This happened right after I installed "react-native-svg": "^6.4.1" and "react-native-svg-charts": "^5.2.0".
My package.json is
"dependencies": {
"react": "16.0.0",
"react-native": "0.51.0",
"react-native-svg": "^6.4.1",
"react-native-svg-charts": "^5.2.0",
"react-navigation": "^1.5.11",
"react-navigation-redux-helpers": "^1.0.5",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-logger": "^3.0.6",
"redux-persist": "^5.4.0"
},
"devDependencies": {
"#babel/core": "^7.0.0-beta.52",
"babel-jest": "23.2.0",
"babel-loader": "^7.1.5",
"gulp-babel": "^7.0.1",
"babel-preset-react-native": "2.1.0",
"jest": "23.3.0",
"react-test-renderer": "16.4.1"
},
"jest": {
"preset": "react-native"
}
I've tried a few other things as well, i've removed the node_modules directory about 150 times and reinstalled. always the same error. I've installed #babel/core and babel-core. I've changed the version numbers, i've moved them around from dependencies to devDependencies and back again. nothing is working.
When I do npm install - everything seems to install just fine
When I do react-native run-android it runs through the code, loads it onto the emulated device
Installing APK 'app-debug.apk' on 'Nexus_6_API_28(AVD) - 9' for app:debug
Installed on 1 device.
BUILD SUCCESSFUL
Total time: 10.373 secs
However, immediately after that, when it runs on the device I receive the red screen of death.
Bundling index.js [development, non-minified] 0.0% (0/1), failed.
error: bundling failed: Error: Cannot find module '#babel/core' (While processing preset: "/Code/nr/node_modules/babel-preset-react-native/index.js")
Well, after a few hours it seems that at least one of the above DID work. the remaining issue was closing the Metro Bundler terminal and starting a new one. Thanks to a comment on the accepted answer from TransformError with babel-preset-react-native/index.js

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"