Unable to resolve react-native-swiper - react-native

Relatively new to react native. Issued the following commmands to create a new react native project:
create-react-native-app SwiperExample
cd SwiperExample
npm install --save react-native-swipe-gestures
I modified App.js and included
import Swiper from 'react-native-swiper';
When I go to test using npm start, I the following error:
Unable to resolve react-native-swiper" from "./C:\Users\sue\ReactNativeApps\SwiperExample\App.js"
Failed building JavaScript bundle
My package.json include the following dependecies
"dependencies": {
"expo": "^25.0.0",
"react": "16.2.0",
"react-native": "0.52.0",
"react-native-swipe-gestures": "^1.0.2"
}
Any suggestions what is wrong?

You are doing a wrong import
Change this
import Swiper from 'react-native-swiper';
By
import Swiper from 'react-native-swiper-gestures';
Or install the correct package in case you installed the wrong one
npm install --save react-native-swipe

Related

Error: Failed to initialize react-native-reanimated library

Trying to create a drawer navigator in React Native using VSCode.
import { createDrawerNavigator } from '#react-navigation/drawer';
const Drawer = createDrawerNavigator();
When I get this error:
Error: Failed to initialize react-native-reanimated library, make sure you followed installation steps here: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation/
Make sure reanimated's babel plugin is installed in your babel.config.js (you should have 'react-native-reanimated/plugin' listed there - also see the above link for details)
Make sure you reset build cache after updating the config, run: yarn start --reset-cache, js engine: hermes
I made sure that everything in babel.config.js is correct:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: ['react-native-reanimated/plugin'],
};
I added the following import to the top my root file (App.js):
import 'react-native-gesture-handler';
I reset my cache too using:
npm cache clean --force
Here are also all of my packages:
...
...
...
"dependencies": {
"#react-navigation/drawer": "^6.5.5",
"#react-navigation/native": "^6.1.1",
"#react-navigation/native-stack": "^6.9.6",
"react": "18.1.0",
"react-native": "0.70.6",
"react-native-gesture-handler": "^2.8.0",
"react-native-reanimated": "^2.13.0",
"react-native-safe-area-context": "^4.4.1",
"react-native-screens": "^3.18.2"
},
...
...
...
Just ran into this issue, was fixed by running
npm start -- --reset-cache
Try installing preset by
npm i metro-react-native-babel-preset --save-dev
and then
npm start -- --reset-cache

Invariant Violation: ViewPropTypes has been removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'

Since the ViewPropTypes has been removed from 'react-native' and the packages using it didn't update. this error appears after building the app
ERROR Invariant Violation: ViewPropTypes has been removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'.
ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
packages I'm using:
"#react-native-clipboard/clipboard": "^1.10.0",
"#react-native-community/checkbox": "^0.5.12",
"#react-native-firebase/app": "^14.11.0",
"#react-native-firebase/auth": "^14.9.4",
"#react-native-firebase/database": "^14.11.0",
"#react-native-firebase/firestore": "^14.11.0",
"#react-native-google-signin/google-signin": "^7.2.2",
"#react-native-masked-view/masked-view": "github:react-native-masked-view/masked-view",
"#react-native-picker/picker": "^2.4.1",
"#react-navigation/bottom-tabs": "^6.3.1",
"#react-navigation/native": "^6.0.10",
"#react-navigation/stack": "^6.2.1",
"axios": "^0.27.2",
"base-64": "^1.0.0",
"num-words": "^1.2.2",
"numeral": "^2.0.6",
"pdf-lib": "^1.17.1",
"react": "17.0.2",
"react-native": "^0.69.0",
"react-native-blob-util": "^0.16.1",
"react-native-country-picker-modal": "^2.0.0",
"react-native-date-picker": "^4.2.2",
"react-native-fbsdk-next": "^8.0.5",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "^2.5.0",
"react-native-html-to-pdf": "^0.12.0",
"react-native-pdf": "^6.5.0",
"react-native-picker-select": "^8.0.4",
"react-native-progress": "^5.0.0",
"react-native-radio-input": "^0.9.4",
"react-native-ratings": "^8.1.0",
"react-native-safe-area-context": "^4.2.5",
"react-native-screens": "^3.13.1",
"react-native-share": "^7.5.0",
"react-native-signature-canvas": "^4.3.1",
"react-native-vector-icons": "^9.1.0",
"react-native-webview": "^11.21.2",
"react-scripts": "^5.0.1"
Any solution?
I can recommend doing the steps outlined in this github discussion.
Steps
Install patch-package, this will later be used to make the changes more persistent.
Install deprecated-react-native-prop-types by running npm install deprecated-react-native-prop-types or yarn add deprecated-react-native-prop-types
Now you have to hack the node_modules. Go to node_modules/react-native/index.js starting around line 436 and change this:
// Deprecated Prop Types
get ColorPropType(): $FlowFixMe {
invariant(
false,
"ColorPropType has been removed from React Native. Migrate to " +
"ColorPropType exported from 'deprecated-react-native-prop-types'.",
);
},
get EdgeInsetsPropType(): $FlowFixMe {
invariant(
false,
"EdgeInsetsPropType has been removed from React Native. Migrate to " +
"EdgeInsetsPropType exported from 'deprecated-react-native-prop-types'.",
);
},
get PointPropType(): $FlowFixMe {
invariant(
false,
"PointPropType has been removed from React Native. Migrate to " +
"PointPropType exported from 'deprecated-react-native-prop-types'.",
);
},
get ViewPropTypes(): $FlowFixMe {
invariant(
false,
"ViewPropTypes has been removed from React Native. Migrate to " +
"ViewPropTypes exported from 'deprecated-react-native-prop-types'.",
);
},
to this:
// Deprecated Prop Types
get ColorPropType(): $FlowFixMe {
return require("deprecated-react-native-prop-types").ColorPropType
},
get EdgeInsetsPropType(): $FlowFixMe {
return require("deprecated-react-native-prop-types").EdgeInsetsPropType
},
get PointPropType(): $FlowFixMe {
return require("deprecated-react-native-prop-types").PointPropType
},
get ViewPropTypes(): $FlowFixMe {
return require("deprecated-react-native-prop-types").ViewPropTypes
},
Run npx patch-package react-native to save the patch.
Rebuild the app.
Only thing to keep in mind is that this patch will need to be reapplied with every upgrade to react-native, or until the libraries in question are updated to import from deprecated-react-native-prop-types instead.
Props to goguda for providing this answer.
I had the same error I followed the following steps and I resolved it. It arises because react-native has removed the view prop types from the library but still some external modules require the use of it.
Run the command in the terminal
npm i deprecated-react-native-prop-types#2.2.0
Go to the node modules and find the module that you are using in my case it was "react-native-camera"
Navigate into the src folder of the module file (in my case it was in RNCamera.js) and look for
import {
findNodeHandle,
Platform,
NativeModules,
ViewPropTypes,
requireNativeComponent,
View,
ActivityIndicator,
Text,
StyleSheet,
PermissionsAndroid,
} from 'react-native';
In the following code remove the ViewPropTypes and paste the following command below this
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
save the file and run it again, Hope it helps <3
I had the same error using react-native-camera. I fix it by installing npm i deprecated-react-native-prop-types#2.2.0 and replacing in node_modules/react-native-camera
all imports in files.
import { ViewPropTypes } from 'react-native';
for
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
In case anyone is getting the error with react-native-snap-carousel this is another way to fix it:
npm i --save react-native-snap-carousel#4.0.0-beta.6
github issue
I had the same error using react-native-snap-carousel. I fix it by replacing in node_modules/react-native-snap-carousel
Check All files and change this import
import { ViewPropTypes } from 'react-native';
with this and this error gone
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
I was facing this problem (Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable.) when I used drawer navigation
so I follow this step
I hope this will help someone
EDIT -
For me.. This error represented a mismatch violation with an older version of Expo Go in the simulator and the version of Expo Cli I was running. It was important that I upgraded each version of Expo one version at a time. It had nothing to do with my React or React Native code. As of Expo 46, expo upgraded the ios simulator with a prompt so the fix below i only relevant below version 46.
In my case, I am using Expo managed Workflow and this error popped up after I upgraded Expo Go on the ios simulator, which prompted me to have to upgrade Expo because the simulator wouldn't allow the version of Expo I was using (43) . After upgrading Expo, and running the simulator, I was greeted with this error, which sent me down a rabbit hole, (where this question is one of the only relevant search results) of trying to upgrade react native to be compatible with the new Expo version and so on. However, this error persisted no matter what version of react native I was using. So finally I tested a different project on the same simulator and found that the actual simulator was throwing the same error on a new project with all the latest versions.
My solution was too simple.
Install a new Simulator with the version of Expo the project is running on. While in the root of the Expo project, in the terminal, I ran
expo client:install:ios
After that, for this project these exact errors completely went away and the Simulator ran fine. I know that this is probably not a long-term fix for the actual error and that upgrading Expo and React Native is going to be necessary and this may not be the issue for many people, but in order to keep working on the project, this allowed me to move forward.
This works for me, just installed these packages. Try it, it might help you as well.
expo install react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context #react-native-community/masked-view
I had the same issue after upgrading to the new RN v0.69. Changing node_modules/react-native-camera would solve the problem locally. However, we know that when the node dependencies need to be installed from scratch - in a CI/CD process for example - the changes at 3rd party library need to be done over again. So, a better solution I suggest is to intercept the react-native-camera component at build runtime level using the babel-plugin-module-resolver as suggested here https://github.com/psycheangel/deprecated-with-module-resolver. I did another way because this solution did not work for me since it's more generic and got conflict with other stuffs I have on my project. Still using the same babel resolver plugin but to address the specific problem with react-native-camera component, this is the way I did based on the above solution by psycheangel:
Step 1
Install the babel resolver plugin and the turn around dependency:
npm install --save-dev babel-plugin-module-resolver deprecated-react-native-prop-types
or
yarn add --dev babel-plugin-module-resolver deprecated-react-native-prop-types
Step 2
create resolver/react-native/index.js with this code:
import * as ReactNative from 'react-native'
import * as DeprecatedPropTypes from 'deprecated-react-native-prop-types'
delete ReactNative['ColorPropType']
delete ReactNative['EdgeInsetsPropType']
delete ReactNative['ImagePropTypes']
delete ReactNative['PointPropType']
delete ReactNative['TextInputPropTypes']
delete ReactNative['TextPropTypes']
delete ReactNative['ViewPropTypes']
module.exports = {
...ReactNative,
...DeprecatedPropTypes,
}
Step 3
add module resolver plugin config to babel.config.js:
const path = require('path')
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
[
'module-resolver',
{
root: ['.'],
resolvePath(sourcePath, currentFile) {
if (
sourcePath === 'react-native' &&
currentFile.includes('react-native-camera/src/RNCamera.js')
) {
console.log('resolver', sourcePath, currentFile)
return path.resolve(__dirname, 'resolver/react-native')
}
},
},
],
],
}

react-native-svg not resolved | victory-native

I am trying to work with victory-native package for graph for react-native platform. I have installed both victory-native and react-native-svg with --save command. And then I also linked them with
react-native link but now when I do react-native start it throws the following error:
error: bundling failed: Error: While trying to resolve module `react-native-
svg` from file `/Users/keshav/projects/PropertyFinder/node_modules/victory-
native/lib/components/victory-primitives/line.js`, the package
`/Users/keshav/projects/PropertyFinder/node_modules/react-native-svg/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved
(`/Users/keshav/projects/PropertyFinder/node_modules/react-native-svg/index.js`. Indeed, none of these files exist:
* `/Users/keshav/projects/PropertyFinder/node_modules/react-native-svg/index.js(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)`
* `/Users/keshav/projects/PropertyFinder/node_modules/react-native-svg/index.js/index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)`
at ResolutionRequest.resolveDependency
(/Users/keshav/projects/PropertyFinder/node_modules/metro/src/node-
haste/DependencyGraph/ResolutionRequest.js:104:15)
```
My package.json:
"react": "16.3.0-alpha.2",
"react-native": "0.54.2",
"react-native-svg": "^6.3.0",
"react-navigation": "^1.5.7",
"simple-swizzle": "^0.2.2",
"superagent": "^3.8.2",
"victory-native": "^0.17.2"
What is wrong here?
I met the same problem.But the different is i used the 'react-native-tab-navigator'.I've tried many times with different ways until i restarted Xcode and rebuilt the project.I hope this can help you.
Late to the party, but I had to modify my metro.config.js file as follows:
module.exports = {
...
resolver: {
sourceExts: ['js', 'jsx', 'ts', 'tsx']
}
}
I think this is to help metro resolve paths beyond js, jsx, etc.

React Native issue on checkPropTypes

Native. I am getting this issue:
D:\abc\node_modules\react-native\Libraries\Core\ExceptionsManage…:71 Warning: checkPropTypes has been moved to a separate package. Accessing React.checkPropTypes is no longer supported and will be removed completely in React 16. Use the prop-types package on npm instead.
Please help me to know this issue.
My app dependency is:
"dependencies": {
"react": "16.0.0-alpha.12",
}
as informative the error is react has moved the prop-types from react-core to another independent package , so in order to use you need to add that to your project.
add another dependency in package.json
"dependencies": {
"react": "16.0.0-alpha.12",
"prop-types": "15.5.8",
}
and wherever you used to import
import {PropTypes} from React or React.PropTypes
you need to import PropTypes from 'prop-types'

Cannot import react-tap-event-plugin with from node_modules typescript

I am trying to learn react and typescript. And would like to include material-ui in my project. From there homepage I am instructed to install react-tap-event-plugin, which I did and "node_modules/react-tap-event-plugin" does exist!
Now I am supposed to to do this:
import injectTapEventPlugin from 'react-tap-event-plugin';
injectTapEventPlugin();
but the typescript compile tells me, that it cannot find the module.
I tried different variants (using require, importing node_mdules/...), but nothing worked.
How do I set this up correctly?
This is my package.json:
{
"private": true,
"scripts": {
"dev": "lite-server"
},
"dependencies": {
"react": "^0.14.0",
"react-dom": "^0.14.0",
"fbjs": "^0.2.1",
"react-tap-event-plugin": "0.2.0",
"material-ui": "^0.14.0"
}
}
You need to install definition file (.d.ts) for react-tap-event-plugin. You can do it with typings by executing the following :
if you don't have typings installed npm install typings --global
typings install dt~react-tap-event-plugin --save
Also, be sure to reference typings/index.d.ts in tsconfig.json.