Aws-sdk-js: Using the npm module in the browser

Created on 11 Nov 2015  路  7Comments  路  Source: aws/aws-sdk-js

Hi,

I ma trying to use the aws-sdk module in the browser (with webpack) by doing:
var AWS = require('aws-sdk');

When I try to get Cognito credentials it fails with the following error:
TypeError: AWS.CognitoIdentity is not a function
at CognitoIdentityCredentials.AWS.CognitoIdentityCredentials.AWS.util.inherit.createClients
at CognitoIdentityCredentials.refresh
at CognitoIdentityCredentials.get

It seems that it is not initialising the CognitoIdentity service.
If I require the dist file it works fine:
require('../../node_modules/aws-sdk/dist/aws-sdk');
but I would like to require the module instead of the specific file.

Is there any way to make this work with the module require?

Thanks

feature-request

Most helpful comment

There was some discussion on how to use the SDK with webpack in #603. A few solutions were proposed, but I'm not sure if they'd work for everyone. Webpack support seems pretty popular so I'm going to mark this ticket as a feature request and keep it open for now.

All 7 comments

Hi @nowakj,

Have you tried using our script package for the browser? You can find more on how to use it in our user guide.

Hi jeskew,

I am able to use the packaged files that come in the 'dist' directory just fine.
However the model we have for our product is to do the packaging with webpack and use npm modules directly with 'require' or 'import'. I was hoping we could do the same with the aws-sdk npm as this would be more consistent with our approach.

Thanks,
Jacek

There was some discussion on how to use the SDK with webpack in #603. A few solutions were proposed, but I'm not sure if they'd work for everyone. Webpack support seems pretty popular so I'm going to mark this ticket as a feature request and keep it open for now.

I was able to solve the problems described in #603, so the module loads fine. but than fails at runtime as the CognitoIdentity service is not loaded.
It would be great if you could add webpack support. thanks!

Indeed, it would be really beneficial if the SDK was updated rather than us having to work around specific issues by trial and error.

Support for webpack was added in version 2.6.0

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.

Was this page helpful?
0 / 5 - 0 ratings