Undefined is not an object (evaluating '_expo.Asset.loadAsync') - react-native

I'm creating a project with React-Native, and currently when I try to compile my code I get an error saying undefined is not an object (evaluating '_expo_.Asset.loadAsync')
I'm not entirely sure what had caused this, for I entered a lot of code prior to compiling the project. However, from what I gathered this may have something to do with the fonts I'm importing?
currently this is what my code looks like for importing the font.
async componentDidMount() {
await cacheFonts({
georgia: require('../assets/fonts/Georgia.ttf'),
regular: require('../assets/fonts/Montserrat-Regular.ttf'),
light: require('../assets/fonts/Montserrat-Light.ttf'),
});
this.setState({ fontLoaded: true });
}

This worked for me in similar code:
Install :
npm install expo-font
import * as Font from 'expo-font';
...
...
async componentDidMount() {
await Font.loadAsync({
'josefin-sans-regular': require('./assets/fonts/JosefinSans-Regular.ttf')
});
this.setState({ fontLoaded: true });
}

You didn't show the error-causing code. But you seem to have called in the entire module of Expo.
Maybe you used import * as Expo from "expo" and Expo.Asset.loadAsync
With SDK 33, we’re deprecating imports of most modules from the expo package. Each module must be installed and used.
You can run expo install expo-asset
import { Asset } from 'expo-asset';
...
Asset.loadAsync(modules)
If you want to use it as it is now, you can use this module. expo-codemod

Related

How do you resolve the 500 error "Navigator is not defined" when installing third-party plugins in a Nuxt 3 app?

I am currently unable to use third-party plugins in my Nuxt 3 application. Here's what my code/setup looks like:
In my package.json I have the following dependency: "#braze/web-sdk": "^4.6.1"
In my plugins/ directory, I have a braze.client.js file
Within the braze.client.js file, I have the following:
import * as braze from '#braze/web-sdk'
export default defineNuxtPlugin(() => {
braze.initialize(apiKey, {
baseUrl: apiEndpoint
})
return {
provide: {
openSession
}
}
})
Within my nuxt.config.ts, I added the following (since my project has Vite, I followed Braze's documentation here: https://www.braze.com/docs/developer_guide/platform_integration_guides/web/initial_sdk_setup/#vite):
optimizeDeps: {
exclude: ['#braze/web-sdk']
}
Then within my <script> tags within the page/component, I have the following:
const { $openSession } = useNuxtApp()
onMounted(() => {
$openSession()
})
All the steps above continue to create a "500 navigator is not defined" error and I'm stumped with how I can resolve it.
I tried using beforeOnMount, not using as lifecycle hook, as well as placing $openSession() within an if statement:
if (process.client) {
}
Yet no matter what, it still renders the 500 error.

BackgroundTask.define not started

react-native-background-task
I want the code to run back in time. I'm trying to use react-native-background-task. But BackgroundTask.define does not start.
import React from 'react'
import { Text } from 'react-native'
import BackgroundTask from 'react-native-background-task'
BackgroundTask.define(() => {
console.log('Hello from a background task')
BackgroundTask.finish()
})
export default class Home extends React.Component {
componentDidMount() {
BackgroundTask.schedule({
period:1
})
}
render() {
return <Text>Hello world</Text>
}
}
this is due to linking issue
Android
he linking of the library can be done automatically by running:
$ react-native link react-native-background-task
One manual step is still needed -
in your project file android/app/src/main/java/myapp/MainApplication.java, add the following to the end of the onCreate() method:
BackgroundTaskPackage.useContext(this);
iOS
For iOS support, this library relies on version 2.0.x of react-native-background-fetch which can be installed as follows:
$ npm install react-native-background-fetch#2.0.x --save
$ react-native link react-native-background-fetch
This library will behave correctly on iOS as long as react-native-background-fetch is installed alongside it, and has been linked with your project.

Expo start don't works after Upgrading Expo 26 to 32

After upgrading expo from: SDK 26 to SDK 32, I have the following issue when I use expo run emulator or expo app:
/Users/name user/project name/node_modules/expo/AppEntry.js: Cannot read property ‘1’ of undefined
AppEntry.js:
import { KeepAwake, registerRootComponent } from 'expo';
import App from '../../App';
if (__DEV__) {
KeepAwake.activate();
}
registerRootComponent(App);
package.json:
{
“main”: “node_modules/expo/AppEntry.js”,
“private”: true,
“scripts”: {
“test”: “node ./node_modules/jest/bin/jest.js --watchAll”
},
“jest”: {
“preset”: “jest-expo”
},
“dependencies”: {
“#expo/samples”: “2.1.1”,
“babel-preset-expo”: “^5.1.1”,
“expo”: “^32.0.0”,
“npm”: “^4.6.1”,
“react”: “16.5.0”,
“react-native”: “https://github.com/expo/react-
native/archive/sdk- 32.0.0.tar.gz”,
“react-native-animatable”: “^1.2.4”,
“react-native-device-info”: “^0.21.5”,
“react-native-drawer”: “^2.5.0”,
“react-native-drawer-menu”: “^0.2.5”,
“react-native-elements”: “^0.19.1”,
“react-native-fetch-polyfill”: “^1.1.2”,
“react-native-geocoder”: “^0.5.0”,
“react-native-geocoding”: “^0.3.0”,
“react-native-google-maps-directions”: “^2.0.0”,
“react-native-keyboard-spacer”: “^0.4.1”,
“react-native-maps”: “^0.21.0”,
“react-native-masked-text”: “^1.6.5”,
“react-native-qrcode-svg”: “^5.1.1”,
“react-native-select-input-ios”: “^1.2.0”,
“react-native-swipeable”: “^0.6.0”,
“react-native-swiper”: “^1.5.13”,
“react-native-touch-id”: “^4.0.4”,
“react-native-vector-icons”: “^4.6.0”,
“react-navigation”: “^3.0.9”
},
“devDependencies”: {
“#babel/core”: “^7.4.3”,
“#babel/preset-env”: “^7.0.0-beta.47”,
“gulp-babel”: “^7.0.1”,
“jest-expo”: “^32.0.0”
}
}
EDIT:
After adjusting at the suggestion, I'm getting this error:
Users/user name/project name/App.js: Cannot read property 'filename' of undefined
Any ideas on potential solutions to try? Any help would be greatly appreciated!
Looking at the issue log for expo, I see someone else had a similar issue when updating from:
SDK version 30 to SDK version 31
and the issue was related to their babel configuration. Perhaps you're dealing with the same issue, maybe you could try the solution they suggested and see if that resolves your issue as well since you're updating from SDK version 26.
Here is what they suggested:
Install the latest version of babel-plugin-module-resolver:
npm i --save-dev babel-plugin-module-resolver#latest
alternatively:
yarn add babel-plugin-module-resolver#latest
Additionally, others had to change their .babelrc contents to use the "babel-preset-expo" preset:
.babelrc
{
"presets": ["babel-preset-expo"]
}
Hopefully that helps!

React Native MQTT Module `url` does not exist in the Haste module map

I want to explore this project https://github.com/mqttjs/MQTT.js within the React Native environment. So I did this:
react-native init myproject
npm install --save mqtt
Then I pasted this sample code from the mqttjs into my App.js a bit after the "Welcome to React Native" component.
var mqtt = require('mqtt')
var client = mqtt.connect('mqtt://test.mosquitto.org')
client.on('connect', function () {
client.subscribe('presence', function (err) {
if (!err) {
client.publish('presence', 'Hello mqtt')
}
})
})
client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString())
client.end()
})
But when I run react-native run-android, I get a compilation error with a message like
Module url does not exist in the Haste module map
I tried replacing mqtt://test.mosquitto.org with a url to my own mosquitto broker with some of these values: mqtt://192.168.0.20, tcp://192.168.0.20, 192.168.0.20. But all these still generated the same error.
What am I doing wrong?
You can solve this by explicitly installing the url module:
npm install url

Cannot read property 'style' of undefined React Native

I removed some of unused dependencies from package.json file and then I did rm -rf node_modules and then npm install.
If I now build my project in Xcode I do not get any errors, but If I try yo run it in a simulator I get red screen as follows:
In the simulator I get :
TypeError: Cannot read property 'Symbol(Symbol.iterator)' of null
at launchEditor (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/react-native/local-cli/server/util/launchEditor.js:153:29)
at Object.handle (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/react-native/local-cli/server/middleware/openStackFrameInEditorMiddleware.js:17:7)
at next (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/connect/lib/proto.js:174:15)
at Object.handle (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/react-native/local-cli/server/middleware/getDevToolsMiddleware.js:74:7)
at next (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/connect/lib/proto.js:174:15)
at Object.handle (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/react-native/local-cli/server/middleware/getDevToolsMiddleware.js:74:7)
at next (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/connect/lib/proto.js:174:15)
at Object.compression [as handle] (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/compression/index.js:205:5)
at next (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/connect/lib/proto.js:174:15)
at IncomingMessage.<anonymous> (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/react-native/local-cli/server/middleware/loadRawBodyMiddleware.js:20:5)
I do not have idea what's going on. Any idea how to solve it?
EDIT
Scene.js is from react-native router-flux navigation:
/**
* Copyright (c) 2015-present, Pavel Aksonov
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import React, { PropTypes } from 'react';
import { ViewPropTypes, Text } from 'react-native';
export default class extends React.Component {
// #todo - should all props be documented/specified here?
static propTypes = {
tabBarStyle: ViewPropTypes.style,
tabBarSelectedItemStyle: ViewPropTypes.style,
tabBarIconContainerStyle: ViewPropTypes.style,
tabBarShadowStyle: ViewPropTypes.style,
tabSceneStyle: ViewPropTypes.style,
tabStyle: ViewPropTypes.style,
tabTitleStyle: Text.propTypes.style,
tabSelectedTitleStyle: Text.propTypes.style,
tabTitle: PropTypes.string,
};
render() {
return null;
}
}
So I had this issue as well and your post helped me solve it. React Native Router Flux was updated roughly 2 weeks ago, where View.propTypes was deprecated for the new ViewPropTypes. Here's the commit for it. https://github.com/aksonov/react-native-router-flux/commit/36dc20418987850677c52905beda59310a0500c3
The issue is that when this update was committed to the live branch the library version was not incremented from 3.37.0 so if you have done an npm install after that commit was implemented, your package would update with the new change, but you would most likely be none the wiser to what they had done (unless you read the commit updates for every package you use in a project)
I found that reverting react-native-router-flux to an earlier version fixed this issue. I used 3.36.0
npm install react-native-router-flux#3.36.0 --save