Jest testing :: Test failed and error routing to \react-native-vector-icons - android

Hi i have been trying to run 'npm test' faced a couple of issues like this with native-base but resolved by placing 'native-base-shoutem-theme|||tcomb-form-native' in transformIgnorePatterns key in my Package.json file.
but haven't found a solution with react-native-vector-icons as shown below
myapp#0.0.1 test D:\ReactWorkSpace\myapp
jest
PASS tests\index.ios.js
FAIL tests\index.android.js
● Test suite failed to run
D:\ReactWorkSpace\myapp\node_modules\native-base\node_modules\react-native-vector-icons\Ionicons.js:6
import createIconSet from './lib/create-icon-set';
^^^^^^
SyntaxError: Unexpected token import
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
at Object.<anonymous> (node_modules/native-base/dist/src/basic/IconNB.js:5:15)
at Object.<anonymous> (node_modules/native-base/dist/src/index.js:16:13)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 3.189s, estimated 8s
Ran all test suites.
npm ERR! Test failed. See above for more details
my package.json file is
{
"name": "myapp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"js-base64": "^2.1.9",
"moment": "^2.18.1",
"native-base": "^2.2.1",
"react": "16.0.0-alpha.12",
"react-native": "0.46.0",
"react-native-animatable": "^1.2.2",
"react-native-button": "^2.0.0",
"react-native-drawer": "^2.3.0",
"react-native-linear-gradient": "^2.2.0",
"react-native-material-design": "^0.3.7",
"react-native-material-kit": "^0.4.1",
"react-native-material-ui": "^1.12.0",
"react-native-vector-icons": "^4.2.0",
"react-navigation": "^1.0.0-beta.11",
"react-toolbox": "^2.0.0-beta.12",
"render-if": "^0.1.1"
},
"devDependencies": {
"babel-jest": "20.0.3",
"babel-preset-react-native": "2.1.0",
"jest": "^20.0.4",
"react-test-renderer": "16.0.0-alpha.12"
},
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(?!react-native|native-base-shoutem-theme|#shoutem/animation|#shoutem/ui|tcomb-form-native)"
]
}
}

Add this to your package.json. It solves your problem :)
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"/node_modules/(?!native-base)/"
],
...
}

Related

Error creating APK Build with React Native having EXPO

I'm trying to use to build an Android APK in my React Native app having expo installed. I've tried in many ways... and always had the same problem telling that some package from Android doesn't exist. This is only a example because the error is replicated with many Android packages.
> Task :expo-modules-core:compileReleaseJavaWithJavac
[stderr] /home/expo/workingdir/build/node_modules/expo-modules-core/android/src/main/java/expo/modules/core/ViewManager.java:3:
error: package android.content does not exist
[stderr] import android.content.Context;
I think this error could be related with versions or versions configuration. I don't know if it could be Java SKD, Expo or something like that.
If anyone could help me please!!
openjdk version "11.0.15" 2022-04-19 LTS
OpenJDK Runtime Environment Zulu11.56+19-CA (build 11.0.15+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)
package.json
{
"name": "AppNative",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"format:all": "eslint . --fix && prettier . --write",
"prepare": "husky install"
},
"dependencies": {
"#react-navigation/native": "^6.0.10",
"#react-navigation/native-stack": "^6.6.2",
"#storybook/addon-knobs": "^6.4.0",
"#types/react-native": "^0.67.3",
"expo": "^45.0.6",
"expo-dev-client": "~1.0.0",
"expo-device": "~4.2.0",
"expo-notifications": "~0.15.4",
"expo-updates": "~0.13.4",
"native-base": "^3.4.7",
"react": "17.0.1",
"react-native": "0.68.2",
"react-native-safe-area-context": "^3.2.0",
"react-native-screens": "^3.13.1",
"react-native-svg": "^12.1.1",
"react-native-webview": "^11.22.4",
"webpack-merge": "^5.8.0"
},
"devDependencies": {
"#babel/core": "^7.16.0",
"#babel/helper-builder-react-jsx-experimental": "^7.12.11",
"#babel/plugin-proposal-private-property-in-object": "^7.16.7",
"#babel/runtime": "^7.14.0",
"#react-native-community/eslint-config": "^2.0.0",
"#storybook/addon-actions": "^6.4.20",
"#storybook/addon-essentials": "^6.4.20",
"#storybook/addon-interactions": "^6.4.20",
"#storybook/addon-links": "^6.4.20",
"#storybook/addon-react-native-web": "^0.0.18",
"#storybook/react": "^6.4.20",
"#storybook/testing-library": "^0.0.9",
"#types/jest": "^27.4.1",
"#types/react": "^17.0.43",
"#types/react-test-renderer": "^17.0.1",
"#typescript-eslint/eslint-plugin": "^5.30.0",
"#typescript-eslint/parser": "^5.30.0",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.2",
"babel-plugin-react-native-web": "^0.17.7",
"eslint": "^8.18.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.2.3",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-storybook": "^0.5.7",
"husky": ">=7",
"jest": "^26.6.3",
"lint-staged": ">=10",
"metro-react-native-babel-preset": "^0.66.0",
"prettier": "^2.7.1",
"react-dom": "^17.0.0",
"react-native-web": "^0.17.7",
"react-test-renderer": "17.0.1",
"typescript": "^4.6.3"
},
"resolutions": {
"#types/react": "^17"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
},
"lint-staged": {
"*.{js,ts,jsx,tsx,css,scss,md}": [
"prettier --write",
"eslint --fix"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
After 3 days of searching... I finally found a solution in this github issue.
https://github.com/expo/expo/issues/17862
As #Kudo says to solve the issue I was using another gradle build version. So I had to change it in my build.gradle file. Make sure is 7.0.4
android/build.gradle
dependencies {
classpath('com.android.tools.build:gradle:7.0.4')
}

React Native: Unfortunately, Application has stopped

My app worked properly !
When run android
The application is compiled without error, but returns the message when it's displayed.
Unfortunately, application has stopped
It happened when i install and link these two packages
react-native-push-notification AND react-native-google-analytics-bridge
{
"rnpm": {
"assets": [
"./assets/fonts/"
]
},
"name": "Melkana",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"#ptomasroos/react-native-multi-slider": "0.0.14",
"expo": "^28.0.0",
"expo-analytics": "^1.0.7",
"lodash": "^4.17.10",
"react": "16.3.1",
"react-native": "0.55.3",
"react-native-check-box": "^2.1.0",
"react-native-elements": "^0.19.1",
"react-native-google-places-autocomplete": "^1.3.6",
"react-native-map-clustering": "^1.3.0",
"react-native-maps": "*",
"react-native-modal-picker": "0.0.16",
"react-native-simple-radio-button": "^2.7.2",
"react-native-ui-kitten": "^3.0.1",
"react-native-vector-icons": "^4.6.0",
"react-navigation": "^2.0.2",
"rn-sliding-up-panel": "^1.2.1"
},
"devDependencies": {
"babel-jest": "22.4.3",
"babel-preset-react-native": "4.0.0",
"jest": "22.4.3",
"react-test-renderer": "16.3.1"
},
"jest": {
"preset": "react-native"
}
}
When run this in Android Studio look this logged errors at Logcat
E/AndroidRuntime: FATAL EXCEPTION: Thread-1480
Process: com.melkana, PID: 11733 java.lang.NoSuchMethodError: No static method loadLibrary(Ljava/lang/String;)V in class Lcom/facebook/soloader/SoLoader; or its super classes (declaration of 'com.facebook.soloader.SoLoader' appears in /data/app/com.melkana-2/base.apk)
at com.facebook.react.bridge.ReactBridge.staticInit(ReactBridge.java:18)
at com.facebook.react.bridge.NativeMap.(NativeMap.java:19)
at com.facebook.react.bridge.JSCJavaScriptExecutorFactory.create (JSCJavaScriptExecutorFactory.java:21)
at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:912)
at java.lang.Thread.run(Thread.java:818)
Solution:
In the app/build.gradle
implementation 'com.facebook.fresco:fresco:1.9.0'
implementation 'com.facebook.fresco:animated-gif:1.9.0'
// IN CASE YOU NEED WEBP SUPPORT / MAKE SURE TO CHANGE THIS TOO TO 1.9.0
implementation 'com.facebook.fresco:animated-webp:1.9.0'
implementation 'com.facebook.fresco:webpsupport:1.9.0'
https://github.com/facebook/react-native/issues/20252

Babel error when running ./gradlew assembleRelease

I receive this error after running ./gradlew assembleRelease:
Plugin/Preset files are not allowed to export objects, only functions.
In C:\..\node_modules\babel-preset-expo\index.js
:app:bundleReleaseJsAndAssets FAILED
**FAILURE: Build failed with an exception.**
This is what I have in package.json file:
{
"name": "Mascota24",
"version": "0.1.0",
"private": true,
"devDependencies": {
"babel-preset-stage-0": "^6.24.1",
"react-test-renderer": "16.3.1"
},
"scripts": {
"start": "react-native start",
"android": "react-native run-android",
"ios": "react-native run-ios",
"test": "jest"
},
"jest": {
"preset": "react-native"
},
"dependencies": {
"#babel/preset-react": "^7.0.0-beta.53",
"babel-preset-env": "^1.7.0",
"babel-preset-expo": "^4.0.0",
"babel-preset-react": "^6.24.1",
"babel-preset-react-native": "^2.1.0",
"babel-preset-react-native-stage-0": "^1.0.1",
"react": "16.3.1",
"react-native": "^0.56.0",
"react-native-circle-checkbox": "^0.1.6",
"react-native-modal": "^6.4.0",
"react-native-phone-call": "^1.0.7",
"react-navigation": "^2.6.2",
"react-redux": "^5.0.7",
"redux-thunk": "^2.3.0"
}
}
And this is .babelrc file:
{
"presets": ["babel-preset-expo"],
"env": {
"development": {
"plugins": ["transform-react-jsx-source"]
}
}
}
I've followed almost every post here related with this and none of them helped me :( Thanks for any help
Thanks to #ashutosh pandey for the help, I changed react-native version to:
"react-native": "^0.55"
Then I installed redux and could generate the .apk! :D

is it possible to create a production build with react-native-mapbox-gl?

I have a location based app built with react-native and the react-native-mapbox-gl package (MapBox Maps SDK for React Native). The app runs on both Android and IOS devices with the commands react-native run-android and react-native run-ios respectively.
When i build a production release, the .ipa and .apk files are created successfully, but they fail to install on the devices
(without any specific error messages).
Is there some extra work that i need to do for building a production release with react-native-mapbox-gl?
this is my package.json
{
"name": "MyAppName",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"#mapbox/react-native-mapbox-gl": "^6.1.1",
"babel-eslint": "^6.1.2",
"eslint": "^3.7.1",
"eslint-config-airbnb": "^12.0.0",
"eslint-plugin-import": "^1.16.0",
"eslint-plugin-jsx-a11y": "^2.2.2",
"eslint-plugin-react": "^6.3.0",
"geolib": "^2.0.24",
"mobx": "^3.1.9",
"mobx-react": "^4.1.8",
"prop-types": "^15.6.1",
"react": "16.3.1",
"react-native": "^0.54.4",
"react-native-animatable": "^1.2.4",
"react-native-keyboard-aware-scroll-view": "^0.4.4",
"react-native-modal": "^5.0.0",
"react-native-simple-toast": "0.0.8",
"react-navigation": "^1.5.2",
"tcomb-form-native": "^0.6.11"
},
"devDependencies": {
"babel-jest": "22.2.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-react-native": "4.0.0",
"jest": "22.2.0",
"react-test-renderer": "16.2.0"
},
"jest": {
"preset": "react-native"
},
"rnpm": {
"assets": [
"./src/assets/fonts/"
]
}
}

Unable to run react native app, which was working before.specifically after installation of prop-types module got failed

Following is the error which I receive when I try to run project.
I tried restarting server several times. Even unable to install new modules. (tried installing prop-types)
The development server returned response error code: 500
URL: http://10.0.3.2:8088/index.android.bundle?platform=android&dev=true&hot=false&minify=false
Body: {"from":"C:\\Users\\user\\Desktop\\NewRNPro\\node_modules\\react\\cjs\\react.production.min.js","to":"prop-types","message":"Unable to resolve module `prop-types` from `C:\\Users\\user\\Desktop\\NewRNPro\\node_modules\\react\\cjs\\react.production.min.js`: Module does not exist in the module map or in these directories:\n C:\\Users\\user\\Desktop\\node_modules\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n 1. Clear watchman watches: `watchman watch-del-all`.\n 2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n 3. Reset packager cache: `rm -fr $TMPDIR/react-*` or `npm start --
--reset-cache`.","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]} processBundleResult
BundleDownloader.java:170 access$100
BundleDownloader.java:39 onResponse
BundleDownloader.java:139 execute
RealCall.java:135 run
NamedRunnable.java:32 runWorker
ThreadPoolExecutor.java:1113 run
ThreadPoolExecutor.java:588 run
Thread.java:818
package.json
{
"name": "NewRNPro",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"lottie-react-native": "^2.2.0",
"react": "16.0.0-alpha.12",
"react-native": "0.47.1",
"react-native-collapsible": "^0.9.0",
"react-native-drawer": "^2.3.0",
"react-native-drawer-menu": "^0.2.4",
"react-native-elements": "^0.16.0",
"react-native-gridview": "^0.1.1",
"react-native-image-slider": "^1.1.5",
"react-native-scrollable-tab-view": "^0.6.7",
"react-native-snackbar": "^0.4.3",
"react-native-sqlite-storage": "^3.3.3",
"react-native-vector-icons": "^4.3.0",
"react-navigation": "^1.0.0-beta.11",
"react-redux": "^5.0.6"
},
"devDependencies": {
"babel-jest": "20.0.3",
"babel-preset-react-native": "2.1.0",
"jest": "20.0.4",
"react-test-renderer": "16.0.0-alpha.12"
},
"jest": {
"preset": "react-native"
}
}

Categories

Resources