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

Fix for ERR_MODULE_NOT_FOUND within lambda node14.x runtime #12

Merged

Conversation

hicksy
Copy link
Contributor

@hicksy hicksy commented Apr 7, 2021

Having been working locally without issue, I've now deployed to an AWS lambda function using the node14.x runtime.

As I'm working in node14 my code uses import statements, rather than require. e.g. import {Table, Model} from 'dynamodb-onetable';

Invoking the lambda I receive an ERR_MODULE_NOT_FOUND not found error:

{
    "errorType": "Error",
    "errorMessage": "Cannot find module '/var/task/node_modules/dynamodb-onetable/dist/mjs/Expression' imported from /var/task/node_modules/dynamodb-onetable/dist/mjs/index.js",
    "code": "ERR_MODULE_NOT_FOUND",
    "stack": [
        "Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/node_modules/dynamodb-onetable/dist/mjs/Expression' imported from /var/task/node_modules/dynamodb-onetable/dist/mjs/index.js",
        "    at finalizeResolution (internal/modules/esm/resolve.js:276:11)",
        "    at moduleResolve (internal/modules/esm/resolve.js:699:10)",
        "    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)",
        "    at Loader.resolve (internal/modules/esm/loader.js:86:40)",
        "    at Loader.getModuleJob (internal/modules/esm/loader.js:230:28)",
        "    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:56:40)",
        "    at link (internal/modules/esm/module_job.js:55:36)"
    ]
}

I'm not entirely certain why this works for me locally (maybe I'm running --experimental-specifier-resolution=node flag 🤷‍♂️). But it seems the lambda node14.x runtime definitely doesn't allow ESM imports without the file extension.

Modified src/index.js to specify the file extensions which resolved my issue.

@mobsense mobsense merged commit 29ee871 into sensedeep:main Apr 7, 2021
@mobsense
Copy link
Contributor

mobsense commented Apr 7, 2021

Thank you. That is right.

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 this pull request may close these issues.

None yet

2 participants