Amazon-cognito-identity-js: Latest version breaks webpack build

Created on 23 Sep 2016  路  12Comments  路  Source: amazon-archives/amazon-cognito-identity-js

The latest update (1.5.0) breaks my webpack build. I am getting an error "require not defined" coming from aws-sdk/clients/cognitoidentityserviceprovider.js
screen shot 2016-09-23 at 11 03 21 am

bug

Most helpful comment

Yes, looking into it.

All 12 comments

@itrestian just want to make sure you see this.

Are you using a webpack setup similar to the one in the examples?

Yes followed almost exactly. Below is my webpack config file. (Note that everything works fine when I roll back to 1.2.0)

'use strict';
let webpack = require('webpack');
const AWS_SDK_MAIN = 'aws-sdk/dist/aws-sdk.min';
let DashboardPlugin = require('webpack-dashboard/plugin');

module.exports = {
    devtool: 'eval-source-map',
    entry: ['./app/index.js'] ,
    output: {
        path: __dirname,
        publicPath: '/',
        filename: 'bundle.js'
    },
    resolve: {
        extensions: ['', '.js', '.jsx'],
        alias: {
            'aws-sdk$': AWS_SDK_MAIN
        }
    },
    module: {
        loaders: [
            { exclude: /node_modules/, loader: 'babel',query: {presets: ['react', 'es2015', 'stage-1']} },
            { test: /\.css$/,loader: 'style-loader' },
            { test: /\.css$/, loader: 'css-loader', query: {modules: true, localIdentName: '[local]___[hash:base64:5]'} },
            { test: /\.css$/,loader: 'postcss-loader' },  
            { test: require.resolve(AWS_SDK_MAIN), loader: 'exports?AWS' }
        ],
        noParse:  [
            /aws\-sdk/,
            /aws-cognito-sdk/
        ],
        preLoaders: [
            {
                test: /\.min\.js$/,
                loader: 'source-map'
            }
        ],
    },
    postcss: function (webpack){
        return [
            require('postcss-import')({ addDependencyTo: webpack }),
            require('postcss-cssnext')
        ];
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env': {
                'NODE_ENV': '"debug"' //production, dev, trace, debug, info, warn, error 
            }
        }),
        new DashboardPlugin({ port: 8080 })
    ],

    devServer: {
        historyApiFallback: true,
        contentBase: './',
        colors: true,
        inline: true
    }
};

Any update on this? Getting the same error 馃槩 In my case, rolling down to 1.2.0 now causes errors about the AWS-SDK not being found. Should I be using the full AWS SDK?

Also, I have two Webpack configurations, one for dev and one for production. I only get the require is not defined error on the production build.

I'm working around the issue by copying the src/ folder to my project and installing the AWS-SDK.

Ok, figured out what I was doing wrong, should have been obvious with hindsight 馃檮

@sarah-pixvana, all you should need to do is remove aws-cognito-sdk from module.noParse, and all the AWS_SDK_MAIN stuff too. Worked for me, at least.

I've just updated to Webpack 2 with no problems and everything seems to work fine. I do think that there should be a single file in dist/ with all dependencies rolled in (i.e. no require() statements, ES5/UMD I think?).

A possibly even simpler fix might be to simply not minify the source, and output it to lib/ or something and point main in package.json to the index.js in there.

I think the reason people are tripping up on this is most Webpack configurations have noParse: /\.min\.js$/, at least for production. I think it does make sense, removing it from the configuration DOES feel like a workaround, and it shouldn't be too difficult to implement (happy to do a PR).

Scratch that, I was looking at the wrong tab, it is not working for me after upgrading to Webpack 2.

Sorry for the noise 馃槥

I have created a new web application that is using a new cognito user pool, and am now running into the same issue even locked into version 1.2.0. @itrestian I saw you marked this as a bug, please let me know when your team comes up with a solution. Thanks!

Yes, looking into it.

Same issue, any work-arounds exist for this at present?

This was probably related to Webpack support in the main aws sdk at that point.

https://github.com/aws/aws-sdk-js/issues/1341

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sarah-pixvana picture sarah-pixvana  路  5Comments

guyb1 picture guyb1  路  4Comments

BerndWessels picture BerndWessels  路  5Comments

howardya picture howardya  路  3Comments

kaihendry picture kaihendry  路  4Comments