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 on importing event even with ESM flag #248

Open
IamMrandrew opened this issue Apr 26, 2024 · 0 comments
Open

Error on importing event even with ESM flag #248

IamMrandrew opened this issue Apr 26, 2024 · 0 comments

Comments

@IamMrandrew
Copy link

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));
};
@IamMrandrew IamMrandrew changed the title Error on importing event on ESM mode Error on importing event with ESM flag Apr 26, 2024
@IamMrandrew IamMrandrew changed the title Error on importing event with ESM flag Error on importing event even with ESM flag Apr 26, 2024
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