aws / aws-sdk-js

AWS SDK for JavaScript in the browser and Node.js
https://aws.amazon.com/developer/language/javascript/
Apache License 2.0
7.59k stars 1.55k forks source link

ReferenceError: Can't find variable: ArrayBuffer #871

Closed neeravmehta closed 8 years ago

neeravmehta commented 8 years ago

You need to check for existance of ArrayBuffer before using it. this is happening in hash function for the crypto module. Specifically line 4270 in a development build with only firehose, cognito and mobile analytics services. Search for data.buffer instanceof ArrayBuffer

chrisradek commented 8 years ago

@neeravmehta Can you tell me what environment ArrayBuffer isn't defined in?

neeravmehta commented 8 years ago

Our environment is a javascript/HTML5 mobile app, it uses an older version of webkit compiler.

chrisradek commented 8 years ago

I can add that check for ArrayBuffer to the SDK. I'm not sure that will be enough to fully resolve the issue you're seeing though. Have you tried adding that check and verified it works for your use case?

Just for reference, here's a list of the currently supported browsers: http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/browser-intro.html

neeravmehta commented 8 years ago

Thanks ! That would be great! Yeah I have it working with the ArrayBuffer check.In fact it is already being used with the check elsewhere in your codebase. How long does it take for this makes it to your sdk builder site? Although I am running into a networking error related to credentials, digging deeper to find out what is going on.

chrisradek commented 8 years ago

@neeravmehta I included the check with the just released v2.2.29 of the SDK. I'm going to close this issue, but feel free to open a new one if you find your networking issues are related to the SDK.

neeravmehta commented 8 years ago

@chrisradek Hi, I checked it in latest version, the check still causes error. Probably javascript tries to think of it as a variable, that is not found. Here is the exact error I am getting "Can't find variable: ArrayBuffer"

Here is the check that fixed it for me if (util.isBrowser() && typeof ArrayBuffer !== "undefined" && data && data.buffer instanceof ArrayBuffer) isBuffer = true; instead of if (util.isBrowser() && ArrayBuffer && data && data.buffer instanceof ArrayBuffer) isBuffer = true;

chrisradek commented 8 years ago

What is ArrayBuffer when you hit that line? Just checking for ArrayBuffer should return a falsey value if it is undefined, which is also what your check is doing.

neeravmehta commented 8 years ago

Unfortunately I cannot debug our platform, so i cannot tell you the exact value for ArrayBuffer. But from what I understand it does not know what ArrayBuffer is, hence best guesses it to a variable , that is not defined and throws an error when it sees it being used. This thread helped me understand it

http://stackoverflow.com/questions/3390396/how-to-check-for-undefined-in-javascript

jeskew commented 8 years ago

@neeravmehta Is the application running on Appcelerator?

AdityaManohar commented 8 years ago

@neeravmehta it looks like you may be using a version of JavaScriptCore that is bundling an unsupported version of WebKit.

As @chrisradek mentioned, the linked patch should address any undefined identifiers on a standards compliant JavaScript engine. Even if this patch were to be changed to explicitly check for undefined, there are other issues that you may run into with native JavaScript API support.

There have been other issues reported when using using Appcelerator and Appcelerator like environments that use an outdated version of JavaScriptCore. See #784

neeravmehta commented 8 years ago

@jeskew While it is'nt Appcelerator in particulr but our platform pretty much does the same thing, and it does use an older version of Webkit.

@AdityaManohar Thanks for the update, I have already run into some issues because of this, I am trying to see if I can get this to work as that will reduce our effort significantly. Our other options are to incorporate both iOS and Android sdk for respective environments, or use REST APIs(where we end up redoing a lot of things that aws-sdk does for us)

I am not sure if this is the right forum for this but will just put is out there, does AWS firehose have REST APIs that we can access to put records?

AdityaManohar commented 8 years ago

@neeravmehta AWS Kinesis Firehose does have a public REST API that you can use but you may still need the SDK to sign requests (or some other equivalent Signature Version 4 signer). Here is the API documentation for AWS Kinesis Firehose.

Your other alternative is to try and use Amazon API Gateway to proxy requests to AWS Kinesis Firehose. This becomes trivially simple if you are using unauthenticated roles to put records to Kinesis Firehose.

Let me know if the helps. Here is a comment that I posted on using API Gateway with CloudSearch - the same concepts apply.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.