I am getting this error when trying to run multiple functions in my cloud code while migrating to a local parse-server instance. It was working fine on the parse.com hosted setup.
I've narrowed it down to being in the jrsrasign.js file, however it really is not easy to track down because it's all minimized.
Has anyone encountered this and know what is going on? I explicitly tracked it down to this method for at least one of the instances (Layer initialization) I'm seeing this error:
var signer = require("./node_modules/jsrsasign/lib/jsrsasign.js");
signer.jws.JWS.sign('RS256', header, claim, this.privateKey);
I am also getting this same error (a.replace is not a function) when calling my other cloud functions that all happen at launch, and those are querying on Parse objects.
Any ideas?
I think you should adjust your usage example to match the npm module instructions: https://www.npmjs.com/package/jsrsasign
var r = require('jsrsasign');
r.jws.JWS.sign(....
I don't think this is related to parse-server itself, but your usage of jsrsasign.
I just tried that, after installing jsrsasign via npm, and I'm still getting the same error, although this time it says "r.replace" instead of "a.replace".
@astanton I'm having the exact same issue. Did you ever figure this one out?
@jessalfredsen I did solve it but I cannot remember 100% what the culprit is. I believe it had to do with an object being passed in earlier on instead of the expected string object. I believe it had something to do with a parameter being passed into a request in a third party library I was using, OpenTok, when creating a new session.
Sorry it was a while ago so I just don't remember exactly what the issue was.
@astanton Ok, thanks.. I'll continue to poke around.
@jessalfredsen did you find a solution to this? We are using jsrsasign as part of Layer authentication and have this same issue after migrating to Parse server.
@emkman we did manage to fix it, though I'm not sure our solution is applicable to everyone.
The issue was the way the private layer key was being read from the key file.
I changed
var privateKey = fs.readFileSync(process.cwd() + '/cloud/layer-parse-module/keys/layer-key.js')
to
var privateKey = fs.readFileSync(process.cwd() + '/cloud/layer-parse-module/keys/layer-key.js').toString();
and apparently the .toString() was all it needed.
Let me know if this works.
Great, thank you! Will try it out.
Most helpful comment
@emkman we did manage to fix it, though I'm not sure our solution is applicable to everyone.
The issue was the way the private layer key was being read from the key file.
I changed
var privateKey = fs.readFileSync(process.cwd() + '/cloud/layer-parse-module/keys/layer-key.js')to
var privateKey = fs.readFileSync(process.cwd() + '/cloud/layer-parse-module/keys/layer-key.js').toString();and apparently the
.toString()was all it needed.Let me know if this works.