I apologize in advance for the English, I am relying on a translator.
I have a monorepo schema project with NestJS. When i try to build my microservice, my dist folder shows me a lot of subdierctories instead of a single build file,
like this:
I have identified this behavior when using the aws sdk (Im using specificly the @aws-sdk/client-sqs)
import { Injectable } from '@nestjs/common';
import { SQSClient, SendMessageCommand } from '@aws-sdk/client-sqs';
import { ISQSService } from '../interfaces';
@Injectable()
export class SqsService implements ISQSService {
public async execute(body: unknown) {
try {
const sqsClient = new SQSClient();
const params = {
QueueUrl: process.env.SQS_QUEUE_URL,
MessageBody: JSON.stringify(body),
};
const sendCommand = new SendMessageCommand(params);
console.log('Sending message to sqs');
const result = await sqsClient.send(sendCommand);
console.log(
`Order sent to the queue successfully with the message id ${result.MessageId}`,
body,
);
} catch (error) {
console.log('Error sending message to SQS');
console.log(error);
}
}
}
If I comment all the execute method body or leave without using SQSClient references then the build is generated correctly (just de dist/apps/webhook-proxy/main.js)
Here is my webpack.config.js
const TerserPlugin = require('terser-webpack-plugin');
const lazyImports = [
'@nestjs/microservices/microservices-module',
'@nestjs/websockets/socket-module',
'class-transformer/storage',
];
module.exports = (options, webpack) => {
return {
...options,
target: 'node',
externals: [],
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
keep_classnames: true,
},
}),
],
},
output: {
...options.output,
libraryTarget: 'commonjs2',
},
plugins: [
...options.plugins,
new webpack.IgnorePlugin({
checkResource(resource) {
if (lazyImports.includes(resource)) {
try {
require.resolve(resource);
} catch (err) {
return true;
}
}
return false;
},
}),
],
};
};
Node: v18.19.0 I think this issue is more related to webpack but just in case my nestjs version is nest-core: 10.0.0
Thanks in advance, <3
I'm expecting that all the build be placed in a single file
