I spent more than a day on this issue. At the end, I have tried almost all possible approaches and finally solved the issue by switching to Serverless from ClaudiaJS. For use of everyone I will mention here the approaches I tried with the results.
- Used the same localhost environment inside the build docker container used by the GoCD pipeline (Same node version, same yarn version, Ubuntu 16:04). But issue was still there.
- Removed docker and setup the GoCD pipeline to run directly on the build server (Again used the same node version, same yarn version, Ubuntu 16:04 as I used in my local machine). But again there was no lock and issue was there without any change.
- Committed the node_modules folder and build folder of my local machine to the git repository and used the same node_modules and build files withing the GoCD pipeline without executing
yarn
and without transpiling the code on the build server. But nothing changed.
Finally, I switched to Serverless framework. In the 1st attempt I used Serverless with babel and without webpack even though serverless recommendation is to use webpack. But again the same issue was occurred when the lambda is deployed with the pipeline. The I changed the configuration to use webpack with serverless. Then all the issues were resolved and lambda was deployed successfully. This is the webpack.config.js
I used at the end.
const path = require('path');
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
const build = {
entry: slsw.lib.entries,
resolve: {
extensions: ['.js'],
},
target: 'node',
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
},
],
},
],
},
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
optimization: {
// Do not minimize the code.
minimize: false,
},
performance: {
// Turn off size warnings for entry points
hints: false,
},
externals: [nodeExternals()],
};
module.exports = build;