React native ios error, 'optionalChaining' isn't currently enabled - react-native

Trying to build my react native app I get this error:
error: bundling failed: SyntaxError: /xxxxr/node_modules/react-native/node_modules/react-native/Libraries/Components/Switch/Switch.js: Support for the experimental syntax 'optionalChaining' isn't currently enabled (103:41):
I have added:
{
"presets": ["react-native"],
"plugins": ["#babel/plugin-proposal-optional-chaining"]
}
To my .babelrc but I still get the error. How can I build my project?

Try installing plugin-proposal-optional-chaining plugin as follows:
npm install --save-dev #babel/plugin-proposal-optional-chaining
Try adding below code to your .babelrc:
{
"plugins": [
"#babel/plugin-proposal-optional-chaining"
],
"presets": [
"react-native"
]
}
Hope it will help you.

Related

React native - Jest failed to parse error

I'm trying to test my react-native expo app using jest and testing library. When running npm test i get the following error:
jets config inside package.json:
"jest": {
"testEnviroment": "jsdom",
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"presets": [
"ts-jest"
]
},
I've been stucked in this error for a lot of time and i tried some other configurations or solutions but nothing seems to work. if you can help me i would appreciate it.

Babel - VueJS | Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions. In

i tried to install preset-env for using environment variables. After that, my VueJS project got an error, i tried npm r #babel/preset-env, i tried npm i --save #babel-core but nothing changed. Any thoughts?
{
"presets": [
["env", { "modules": false }],
"stage-3",
],
"plugins": [["transform-runtime", { "polyfill": false, "regenerator": true }]]
}
Problem solved with using Babel version from vue.js webpack template repository.
npm r babel-core
add "babel-core": "^6.22.1" to package.json
npm i

Not able to work with peer dependency in react native

I have one react-native app in which I am using "json-schema-rules" library. Now I have also created one library which is getting used in my react-native app like this "file:../custom_library" in package.json.
Now to resolve the version conflict, I decided to use "json-schema-rules" as a peer dependency in my custom library. So, the package.json is like this
Package.json of my react-native app:
{
"dependencies": {
"json-rules-engine": "^2.3.0",
"custom_library": "file:../custom_library"
}
}
package.json of my custom_library:{
"peerDependencies": {
"json-schema-rules": "^2.3.0"
}
}
Now the problem is, whenever I am using metro bundler, I get an error
error: bundling failed: Error: Unable to resolve module json-rules-engine
json-rules-engine could not be found within the project.
This is the case when I am using it in peerDependencies, I do not get any error if I use this library in dependencies.
Please help.
You can try to add an alias for the module in your project's babel config.
This means that when your custom packages tries to import "json-rules-engine" it will get served the version from the main app.
First install 'babel-plugin-module-resolver' then configure the alias in "module-resolver"
babel.config.js
const config = {
presets: ["module:metro-react-native-babel-preset"],
plugins: [
[
"module-resolver",
{
root: ["./src"],
extensions: [".js", ".jsx", ".ios.js", ".android.js"],
alias: {
"json-rules-engine": require.resolve("json-rules-engine")
}
}
]
]
};
module.exports = config;

App crashes after upgrade expo sdk from 30 to 31

I have updated the SDK using this instruction. And I ran the app. The app shows this error in red screen:
babelHelpers.readOnlyError is not a function. (In
‘babelHelpers.readOnlyError(“newSize”)’, ‘babelHelpers.readOnlyError’
is undefined )
How can I solve this error?
I tried clearing the yarn cache, installing yarn packages again but do not work.
I found this webpage solving my problem.
Add the following in package.json:
"devDependencies": {
"babel-plugin-transform-remove-console": "6.9.4",
"babel-preset-expo": "^5.0.0"
}
make the .babelrc:
{
"presets": ["babel-preset-expo"],
"env": {
"production": {
"plugins": [
"transform-remove-console"
]
}
}
}
Update .babelrc and package.json
Delete node_modules folder
Install babel-plugin-transform-remove-console, babel-preset-expo. Run yarn or npm.
Run expo clearing cache using expo start -c

SyntaxError: Unexpected token import

I have been trying to solve this problem since some days so any help is welcome
When testing my React Native app with Jest, I get the following error with the victory-native package:
SyntaxError: Unexpected token import
I visited many issues and questions which all seem to solve this problem by using the transformIgnorePatterns key for the jest config
The problem is when i use that, I get another error :
TypeError: Cannot set property '_currentElement' of undefined
Jest config
"jest": {
"preset": "react-native",
"transform": {
"^.+\\.js$": "babel-jest"
},
"transformIgnorePatterns": [
"node_modules/(?!react-native|victory-native)/"
]
},
Babel
{
"presets": ["react-native"],
"sourceMaps": true,
"env": {
"test" : {
"presets": ["react-native"],
"plugins": ["transform-es2015-modules-commonjs"]
}
}
}
RN Version: 0.46.2
Jest Version: ^20.0.4
Test command: NODE_ENV=test jest --no-cache
I am completely clueless about this now so any tips or hints would also do.
Thanks in advance!