1

I am trying to deploy my serverless function. My deployment went through without any problem. However, I am encountering issues where AWS lambda console is looking for .mjs extension but the built code is in .js. I have to then manually update the extension for my deployment to work which defeats the purpose. I tried both the outExtension and the outFile config but no luck.

Here's my serverless.yml config:

...
build:
  esbuild:
    bundle: true
    minify: false
    external:
      - "uuid"
    exclude: "*"
    format: esm
    outExtension:
      ".js": ".mjs"

plugins:
  - serverless-offline
...

This is the basic code that I want to deploy:

import { v4 as uuidv4 } from "uuid";

export const hello: any = async (event: any) => {
  return {
    statusCode: 200,
    body: JSON.stringify({
      id: uuidv4(),
      message: "Go Serverless v4! Your function executed successfully!",
    }),
  };
};

The compiled outcome is as follow:

|--handler.js // <=== AWS Lambda expecting handler.mjs
|--handler.js.map
1
  • On first glance I would say its related to format: esm try removing that param. I also dont think you need the outExtension param. Commented Oct 30, 2024 at 11:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.