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

Missing support for .mjs files #700

Closed
vladaman opened this issue Dec 27, 2023 · 0 comments · Fixed by #701
Closed

Missing support for .mjs files #700

vladaman opened this issue Dec 27, 2023 · 0 comments · Fixed by #701

Comments

@vladaman
Copy link

We'd like to move to newer nodejs 18 and 20 which is supported by AWS now. Our setup:

package.json :

{
  "name": "fk-demo-connector",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "index.mjs",
}

index.mjs :

console.log('Loading function');

export const handler = async (event, context) => {
    console.log('Received event:', JSON.stringify(event, null, 2));
   
    return {};  // Echo back the first key value
    // throw new Error('Something went wrong');
};

Running node-lambda:

> node-lambda run --contextFile ../context.json -f ../.env -j event-init.json

node:internal/errors:496
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/vlad/workspace/lambda/fk-demo-connector/index.js' imported from /usr/local/lib/node_modules/node-lambda/lib/main.js
    at new NodeError (node:internal/errors:405:5)
    at finalizeResolution (node:internal/modules/esm/resolve:327:11)
    at moduleResolve (node:internal/modules/esm/resolve:946:10)
    at defaultResolve (node:internal/modules/esm/resolve:1132:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ESMLoader.import (node:internal/modules/esm/loader:524:22)
    at importModuleDynamically (node:internal/modules/cjs/loader:1188:29)
    at importModuleDynamicallyWrapper (node:internal/vm/module:429:21) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v18.18.0

Suggestions:

  • Allow to parameterize extension index.js -> index.mjs
  • Take index.mjs from package.json main key
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

Successfully merging a pull request may close this issue.

1 participant