I am trying to login using ‘aws-amplify’ node module.
I followed the template given [GitHub - grafana/k6-template-es6: Template repository for bundling test projects into single test scripts runnable by k6]
Basic examples run fine, but when I use for ‘aws-amplify’ compilation passes, but throws run time error.
Function which calls ‘aws-amplify’ and causes error:
Note: I have not removed commented lines to show the options already tried.
import {Amplify as amp} from 'aws-amplify';
//import { Auth } from '@aws-amplify/auth';
export function configureAmplify() {
//const { Amplify } = import('aws-amplify');
//const amplifyobj = new Amplify();
amp.configure({
Auth: {
authenticationFlowType: 'CUSTOM_AUTH',
region: process.env.AWS_AUTH_REGION,
identityPoolId: process.env.AWS_AUTH_USER_POOL_ID,
identityPoolRegion: process.env.AWS_AUTH_REGION,
userPoolId: process.env.AWS_AUTH_USER_POOL_ID,
userPoolWebClientId: process.env.AWS_AUTH_USER_POOL_WEB_CLIENT_ID,
}
})
}
Webpack Configuration:
var webpack = require('webpack');
var path = require('path');
const Dotenv = require('dotenv-webpack');
module.exports = {
mode: 'production',
entry: './main.js',
output: {
path: path.resolve(__dirname, 'build'),
libraryTarget: 'commonjs',
filename: 'app.bundle.js',
publicPath: '',//Added with webpack 5.74.0 & node 16.16.0
//globalObject: 'this', //Added for ReferenceError associated in AmplifyLogin
},
plugins: [
new Dotenv(),
/*new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
})*/
],
/*optimization:{
splitChunks: { chunks: 'all' }
},*/
module: {
rules: [
{
test: /\.js$/,
//exclude: /node_modules/,//Added to avoid Window not defined error, not resolved
loader: 'babel-loader',
},
],
},
stats: {
colors: true,
},
target: 'web',
externals: /^(k6|https?\:\/\/)(\/.*)?/,
devtool: 'source-map',
};
Package.json file content
{
"name": "k6-es6",
"version": "1.0.0",
"description": "test project for k6 to use es6 through the power of babel and webpack",
"main": "main.js",
"devDependencies": {
"@babel/core": "^7.4.4",
"@babel/plugin-transform-block-scoping": "^7.14.1",
"@babel/preset-env": "^7.4.4",
"babel-loader": "^8.0.6",
"core-js": "^3.0.1",
"dotenv-webpack": "^8.0.0",
"moment": "^2.24.0",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},
"engines": {},
"scripts": {
"webpack": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"k6"
],
"author": "Mihail Stoykov",
"license": "ISC",
"dependencies": {
"amazon-cognito-identity-js": "^5.2.10",
"aws-amplify": "^4.3.27",
"aws-sdk": "^2.1120.0",
"chai": "^4.3.6",
"chai-json-schema": "^1.5.1",
"cheerio": "^1.0.0-rc.12",
"dotenv": "^16.0.0",
"faker": "^5.5.3",
"googleapis": "^100.0.0",
"ts-node": "^10.9.1",
"typescript": "^4.7.4",
"xml2js": "^0.4.19"
}
}
babel.config.json
{
"presets": [
[
"@babel/preset-env"
]
],
"plugins": [ "@babel/plugin-transform-block-scoping"]
}