Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR (node:2) [DEP0005] Using wrong Buffer in library #30

Open
BrenoRev opened this issue Mar 6, 2025 · 0 comments
Open

ERROR (node:2) [DEP0005] Using wrong Buffer in library #30

BrenoRev opened this issue Mar 6, 2025 · 0 comments

Comments

@BrenoRev
Copy link

BrenoRev commented Mar 6, 2025

When you're running the Lambda function, the deprecation warning is being treated as an error. This is because Lambda handles unhandled promise rejections or exceptions in a way that might trigger the error handler. You can address this by catching and silencing the warning so it doesn't trigger the Lambda error handler, while still allowing the code to execute normally.

"ERROR (node:2) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use node --trace-deprecation ... to show where the warning was created)"

Node v20.11.0
"xlsx-write-stream": "1.0.3"

import { createWriteStream } from 'fs';
import XLSXWriteStream from 'xlsx-write-stream';

export const createExcelFile = (data: {
  xlsxTemplate: Record<string, any> | Array<Record<string, any>>;
  filePath: string;
}): Promise<void> => {
  return new Promise((resolve, reject) => {
    const { xlsxTemplate, filePath } = data;

    const jsonArray: Array<Record<string, any>> = Array.isArray(xlsxTemplate)
      ? xlsxTemplate
      : [xlsxTemplate];

    const jsonKeys: string[] = Object.keys(jsonArray[0]);

    const rows: any[][] = jsonArray.map(row => {
      return jsonKeys.map(key => {
        let value = row[key];

        if (
          value == null ||
          value === undefined ||
          value == 'undefined' ||
          value == 'null' ||
          value == 'NaN'
        ) {
          value = '-';
        }

        return value;
      });
    });

    const xlsxStream = new XLSXWriteStream();
    const writeStream = createWriteStream(filePath);

    xlsxStream.pipe(writeStream);

    xlsxStream.write(jsonKeys);

    rows.forEach(row => {
      xlsxStream.write(row);
    });

    xlsxStream.end();

    writeStream.on('finish', () => {
      console.log('Arquivo XLSX criado com sucesso:', filePath);

      resolve();
    });
    writeStream.on('error', err => {
      console.error('Erro na escrita do arquivo XLSX:', err);
      reject(err);
    });
  });
};

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant