Amazon-cognito-identity-js: [RequireJS issue] - `TypeError: punycode.toASCII is not a function`

Created on 3 Aug 2016  路  8Comments  路  Source: amazon-archives/amazon-cognito-identity-js

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. https://github.com/aws/aws-sdk-js/issues/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 ?

All 8 comments

Let me look into this today.

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

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

Seeing the same issue. Any ideas?

Thanks

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.

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;
                // }

Thanks @AlexanderC!

Does this solve it for everyone?

Yes, that fix works for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kpitzen picture kpitzen  路  3Comments

guyb1 picture guyb1  路  4Comments

m-schrepel picture m-schrepel  路  6Comments

eczajk1 picture eczajk1  路  3Comments

BerndWessels picture BerndWessels  路  5Comments