Cannot find module in custom functions

Issue Description: What’s happening?

Good morning, I am trying to do a simple webhook to send emails. The problem is that after deploying and trying to fetch my webhook function I get the following error “module not found”. Testing locally everything works perfectly the problem only happens after deploy.
my package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "8base Custom Logic",
  "dependencies": {
    "@sendgrid/mail": "^7.1.1",
    "chrome-aws-lambda": "^3.1.1",
    "dotenv": "^8.2.0",
    "graphql-request": "^1.6.0",
    "path": "^0.12.7",
    "pug": "^2.0.4",
    "puppeteer": "^3.1.0"
  }
}

handler.js

import mailer from '../../../shared/mailer';
import sengridTemplates from '../../../shared/sengrind-templates';
import pdfTemplate from './pug-template';

require('puppeteer');
const chromium = require('chrome-aws-lambda');
const pug = require('pug');

export default async (event) => {
  let browser = null;
  try {
    const { form, calculator } = event.data;

    // client message
    const pugTemplate = pug.compile(pdfTemplate);
    const html = pugTemplate(calculator);

    browser = await chromium.puppeteer.launch({
      headless: true,
    });

    const page = await browser.newPage();
    page.setContent(html);

    const pdf = await page.pdf();
    const clientMessage = {
      to: form.email,
      from: 'no-reply@Test.com',
      subject: 'Test subject',
      // setting dynamic template
      templateId: sengridTemplates['calculator-contact'],
      attachments: [
        {
          content: pdf.toString('base64'),
          filename: 'attachment.pdf',
          type: 'application/pdf',
          disposition: 'attachment',
        },
      ],
    };


    // cobuildlab team message
    const teamMessage = {
      to: 'palokesea3@gmail.com',
      from: 'no-reply@Test.com',
      subject: 'Test',
      templateId: sengridTemplates['calculator-team'],
      dynamic_template_data: {
        name: form.name,
        email: form.email,
        message: form.message,
      },
    };

    await mailer.send(teamMessage);
    await mailer.send(clientMessage);


    return {
      statusCode: 200,
      body: JSON.stringify({
        result: 'all ok',
      }),
    };
  } catch (error) {
    // console.error(error)
    if (error.response) {
      return {
        statusCode: 400,
        body: JSON.stringify({
          result: error.response.body,
        }),
      };
    }
    return {
      statusCode: 400,
      body: JSON.stringify({
        result: error.code || error,
      }),
    };
  } finally {
    if (browser !== null) {
      await browser.close();
    }
  }
};    

Reproduce the Issue: What steps can someone take to replicate the problem?

after make deploy i run 8base invoke mail -m request o try make a request with postman

Expected Behavior: What did you expect to happen?

Result:
{
  "statusCode": 200,
  "body": "{\"result\":\"all ok\"}"
}

Actual Behavior: What actually happened?

Server response 500 internal server error, **Cannot find module 'puppeteer'**

update

If I remove puppeteer from the code everything works fine, it seems that the size of the package is causing a problem

1 Like

@evgeny.semushin @eugene.antonevich

We have been investigating this and it seems that the dependencies reach the 50 MB limit or something.

This is because this libraries are recommended on some AWS Lambda blog examples. We are not sure, it would be good to have an error message if that’s the case.

1 Like

Is there any guidance on this? I have a task to generate some pdfs using puppeteer as well, and I’m hitting the same issues.

Hey Justin, we have the same upload size limits currently. Is there a lighter PDF module you can use?

Did you solve the problem?, I have the me issue right now