Skip to content

Error on importing event even with ESM flag #248

Description

@IamMrandrew

Context

Just tried to use this package for local lambda development on my project, which is in ES module.

Version: 2.2.0.
Command that I run:

lambda-local --esm -l entry.js -t 600 --envfile .env -e event/index.js

Here's my event file.

// event/index.js
export const eventData = {
    message: "Hello"
};

Current behaviour

Here's the error that I get.

require() of ES Module /<my_path>/event/index.js from /<my_path>/node_modules/lambda-local/build/cli.js not supported.\nInstead change the require of index.js in /<my_path>/node_modules/lambda-local/build/cli.js to a dynamic import() which is available in all CommonJS modules

Expected behaviour

Use import() for event when --esm flag is provided.

Possible Solution

I have implement a temporary fix on my local, which is hard-coded for ES module. Would like to request on a code change in upcoming release to handle this scenario.

Here's the reference code changes.

// node_modules/lambda-local/build/cli.js
// line 135
var event = async function () {
    if (program.watch)
        return null;
    return await import(utils.getAbsolutePath(eventPath));
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions