Skip to content
This repository has been archived by the owner on Feb 24, 2018. It is now read-only.

[RequireJS issue] - TypeError: punycode.toASCII is not a function #97

Closed
mgoria opened this issue Aug 3, 2016 · 8 comments
Closed

[RequireJS issue] - TypeError: punycode.toASCII is not a function #97

mgoria opened this issue Aug 3, 2016 · 8 comments

Comments

@mgoria
Copy link

mgoria commented Aug 3, 2016

After updating to latest aws-cognito-sdk.js version, which seems to "rely" on AWS SDK v2.3.14, I'm running into below error:

TypeError: punycode.toASCII is not a function

It seems to be an AWS SDK issue (ref. aws/aws-sdk-js#999) that is fixed in v2.3.16.

Is there a way to rebuild aws-cognito-sdk.js with AWS SDK v2.3.16 or greater ?

@itrestian
Copy link
Contributor

Let me look into this today.

@itrestian
Copy link
Contributor

I updated to the newest version of the AWS SDK. Can you check?

@mgoria
Copy link
Author

mgoria commented Aug 4, 2016

I've checked and unfortunately it doesn't work.

With aws-sdk-2.4.12.js it works but with latest aws-cognito-sdk.js it throws the same error (see attached screenshot)

screen shot 2016-08-04 at 2 52 42 pm

@mojojr
Copy link

mojojr commented Aug 16, 2016

Seeing the same issue. Any ideas?

Thanks

@IveGotThePawa
Copy link

IveGotThePawa commented Sep 6, 2016

Same error with the SDK in my big projet. Works fine on a project with (almost) just the SDK included in the html page.

Seems something in my code is interfering with punycode, making it undefined. I didn't find what yet.

EDIT: Seem to be a race condition?

var punycode = require('punycode');

Seems to be evaluated before

punycode = {
    'version': '1.4.1',
    'ucs2': {
        'decode': ucs2decode,
        'encode': ucs2encode
    },
    'decode': decode,
    'encode': encode,
    'toASCII': toASCII,
    'toUnicode': toUnicode
};

This seems quite recent as an older SDK don't have this problem.

@AlexanderC
Copy link

AlexanderC commented Sep 7, 2016

Guys,

It turned out that the Punycode library can conflict with different bundle systems (FYI we're using Webpack).

I've managed to fix the bug by patching the aws-sdk-2.4.14.js sources (non minified!) at line 28126:

                module.exports = punycode;
                // if (
                //     typeof define == 'function' &&
                //     typeof define.amd == 'object' &&
                //     define.amd
                // ) {
                //     define('punycode', function() {
                //         return punycode;
                //     });
                // } else if (freeExports && freeModule) {
                //     if (module.exports == freeExports) {
                //         freeModule.exports = punycode;
                //     } else {
                //         for (key in punycode) {
                //             punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
                //         }
                //     }
                // } else {
                //     root.punycode = punycode;
                // }

@itrestian
Copy link
Contributor

itrestian commented Sep 7, 2016

Thanks @AlexanderC!

Does this solve it for everyone?

@IveGotThePawa
Copy link

Yes, that fix works for me

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants