null is not an object (evaluating 'RCTAsyncStorage.multiMerge') - javascript

I recently upgraded to Expo SDK 43.
I am now getting this error:
The line of code throwing it is:
if (!RCTAsyncStorage.multiMerge) {
I am on the latest version of AsyncStorage.
This seems to be due to my usage of firebase-js-sdk.
Unfortunately as this is an iOS/Android/Web project, it's necessary.
When I mock my Firebase exports, everything works:
const auth = () => {};
const analytics = () => {};
export default { auth, analytics };
But when I use the firebase-js-sdk functions, I get the above message.
This code causes an error (whichever version of auth I use)
let auth = initializeAuth(config, {
persistence: getReactNativePersistence(AsyncStorage),
});
//let auth = getAuth(config);
let analytics = getAnalytics(config);
export default { auth, analytics };

You could avoid that specific error by adding optional chaining (the question mark '?'):
if (!RCTAsyncStorage?.multiMerge) {
It will shortcircuit to undefined (thus making the if false) instead of throwing error from trying to check in the null object.
As to why RCTAsyncStorage would be null, you would have to check where you first get/declare it, and traceback to the point it didn't load, maybe you are using something conflicting from firebase-js-sdk.
Also multiMerge might not be supported always as mentioned in the docs:
multiMerge
[...] NOTE: This is not supported by all native implementations.

Related

Uncaught (in promise) TypeError: Cannot read property 'filter' of undefined

I created a react-app which I deployed online with npm run build, now everything locally works fine but when I try to load a page on my app it gives a error in Container.js ( no idea what this file is and what it does )
i've tried to reinstall all the node_modules without any result so I cloned my repo fresh but still without any result
Container.js:
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _reactRedux = require('react-redux');
var _Container = require('../components/Container');
var _Container2 = _interopRequireDefault(_Container);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
/**
* src/containers/Container.jsx
*/
var mapStateToProps = function mapStateToProps(store, ownProps) {
return {
items: store[ownProps.reduxStoreName].content[ownProps.reduxUid].filter(function (item) {
return item.parentId === ownProps.itemId;
})
};
};
exports.default = (0, _reactRedux.connect)(mapStateToProps)(_Container2.default);
Error in console: Uncaught (in promise) TypeError: Cannot read property 'filter' of undefined
well, like #Pointy mentioned in his comment, it basically means that store[ownProps.reduxStoreName].content[ownProps.reduxUid] is undefined.
It is not the file which is causing the error, its the specific line. When the code reaches this line and tries to execute it- that store[ownProps.reduxStoreName].content[ownProps.reduxUid] parameter is undefined so it crushes.
We cannot tell you where the error is, we'd need the code of your whole app to follow the execution flow.
You have to follow it yourself, and understand why there is not an array in that variable when the code gets there.
As a general idea, try figure out the following:
when and where that variable is initialized?
when and where do you call mapStateToProps?
are you absolutely sure that the code which answers question 1 is executed before the code which answers to question 2? (maybe there is an asynchronous execution problem you didn't think about which causes your code to execute at the wrong order)
if it does- maybe the way you initialize those variables at the beggining is not correct? maybe you use a 3rd party library / function to initialize them, but not actually getting the result you expecting? or maybe you're using it wrong, or parsing the result wrong?

web3.eth.accounts[0] returns undefined

I am new to solidity and was exploring it through a simple webapp. I have a web app which accepts some details and a button pressing which the details should be deployed to the block created by the smart contract. The details are successfully deployed from the remix IDE but give the following exception when entering through the web app.
inpage.js:1 Uncaught Error: Invalid number of arguments to Solidity function
at Object.InvalidNumberOfSolidityArgs (inpage.js:1)
at u.validateArgs (inpage.js:1)
at u.toPayload (inpage.js:1)
at u.sendTransaction (inpage.js:1)
at u.execute (inpage.js:1)
at HTMLButtonElement.<anonymous> ((index):231)
at HTMLButtonElement.dispatch (jquery-3.2.1.slim.min.js:3)
at HTMLButtonElement.q.handle (jquery-3.2.1.slim.min.js:3)
On surfing the internet I found that this could be because the web3.eth.accounts[0] returns 'undefined' which is what is happening in my case.
On the contrary though on displaying web3.eth on the console it does show accounts and the MetaMask address too at index 0.
I read it may be because web3js 1.0 might not be completely supported by MetaMask yet but I am unable to find a solution to it.
Also how to check the version of web3 I am using and how to deprecate to lower if necessary.
This is how I try to access the web3.eth.accounts[0]
web3.eth.defaultAccount = web3.eth.accounts[0];
console.log(web3.eth.defaultAccount); // returns undefined
I also tried the following method but to no avail:
var myAccount;
web3.eth.getAccounts(function(err,res){
if(!err)
{
myAccount = res;
console.log(myAccount);
}
});
This returns the account address but the myAccount variable again returns 'undefined' when used outside the getAccounts method. Also writing the further logic inside the if part does not help giving the above mentioned exception.
I have tried a few things but unable to find the solution. Please guide and correct if I have miss-understood anything.
EDIT
You can find the source code here.
https://github.com/anishsamant/Solidity-Demo
Refer Courses.sol for solidity file
Refer index.html for web app.
Methods in web3 such as getAccounts are asynchronous.
Note
web3 version 1.x.x return promises. So you use promises and you can also implement it with the async/await syntax.
web3 versions 0.x.x do not return promises, you can only use callbacks.
Code for web3 versions 1.x.x (I can only assume you might be using).
const myFunc = async () => {
try {
const myAccounts = await web3.eth.getAccounts();
console.log(myAccounts)
return myAccounts;
} catch (err) {
console.log(err);
}
}
myFunc()

Facebook's GraphRequestManager() undefined, but should be working?

Facebook authentication works great, but when I go to make a Graph request:
const infoRequest = new GraphRequest(
'/me',
{
accessToken: tokenString,
fields: 'email,first_name,name,last_name,picture'
},
this._responseInfoCallback
);
new GraphRequestManager().addRequest(infoRequest).start();
}
I get "TypeError: Cannot read property 'start' of undefined"
Using the Chrome debugger, everything appears like it should be working, and even storing GraphRequestManager as a variable has everything it needs until I call start(). Even using sample code I've found on this site fails when I call start(). Am I missing something obvious?
Here's a little more info. I'm importing with this:
const FBSDK = require('react-native-fbsdk');
const {
GraphRequest,
GraphRequestManager
} = FBSDK;
If I use FBGraphRequest and FBGraphRequestManager instead of above, I get errors stating that GraphReqest, etc aren't functions when I use them. Otherwise, the rest of my code looks very similar to Shivam's, but I get 'Cannot read property 'start' of undefined', so obviously the GraphRequestManager call is failing or isn't defined (which makes no sense to me).
In my experience, the fields you wish to request are specified inside parameters:
AccessToken.getCurrentAccessToken().then(
(data) => {
let accessToken = data.accessToken
const infoRequest = new GraphRequest(
'/me',{
accessToken: accessToken.toString(),
parameters: {
fields: {
string: 'email,first_name,name,last_name,picture'
}
}
},
this._responseInfoCallback.bind(this),
);
new GraphRequestManager().addRequest(infoRequest).start();
})
Ps where did you place the functions? Are they inside the class?

Empty object after `require`

I'm trying to use your relaxed-json in my Electron app. Here is a simple code, GetDeviceList() is triggered on a button-push action:
const driver = require('meteor_driver').MeteorConnection.MeteorConnection;
const relaxed = require('relaxed-json');
const connection = new driver();
function GetDeviceList() {
console.log(connection.port);
console.log("Launching");
console.log(relaxed);
relaxed.transform('[{id:0,},{id:1,},{id:2,},]');
}
The console.log show me an empty object. And I got an error message Uncaught TypeError: relaxed.transform is not a function.
Otherwise, the package works properly when it's not used with electron.
Note that I don't encounter any require-related issue, so the modules must be valid isn't ?

Is there someway to disable all firebase logging to console?

I have created some unit tests for my firebase security rules. Part of this testing is trying to do illegal operations and asserting that they fail.
My problem has to do with noise; when I run the tests using nodeunit, the firebase client spits out several logs similar to this:
FIREBASE WARNING: set at /user failed: permission_denied
I do not want this output when intentionally doing illegal operations as it just results in noise and confusion.
These days there is an option to set the log level on the global firebase object:
import firebase from 'firebase/app';
firebase.setLogLevel('silent')
In our testing suite, we rewrite process.stderr.write to only ignore firebase warnings like so:
Javascript
process.stderr.write = (function(write) {
return function() {
if (!arguments[0].includes("FIREBASE WARNING"))
write.apply(process.stderr, arguments);
};
}(process.stderr.write));
Typescript (including tslint fix)
process.stderr.write = (() => {
// tslint:disable-next-line:no-unbound-method
const write = process.stderr.write;
return function () {
if (!(arguments[0] as string).includes("FIREBASE WARNING")) {
return write.apply(process.stderr, arguments);
}
};
})();
There is no way to disable the security warnings as they are emitted asynchronously by the Firebase SDK. I worked around this by adding a message before the errors:
>>> An intentional security error should be printed after this line...
As Kato said, there doesn't appear to be an official way to disable it. That said, if you really want to, it takes 2 seconds to go into the source, Ctrl+F for "WARNING", and comment out this line:
"undefined"!==typeof console.warn?console.warn(b):console.log(b)

Categories

Resources