1

I'm currently working on a serverless project where I'm using ESBuild to bundle my JavaScript code for AWS Lambda functions. Everything has been working smoothly so far, but I've run into a situation where I need to load a Node.js module that is not natively supported by ESBuild.

Whenever I run the serverless package command, I encounter the following error:

✘ [ERROR] No loader is configured for ".node" files: node_modules/.pnpm/[email protected]/node_modules/nodejs-polars-darwin-arm64/nodejs-polars.darwin-arm64.node

Specifically, I need to use a Node.js module loader to load a module that contains native bindings with a .node extension. However, ESBuild doesn't seem to support this out of the box, and I'm not sure how to configure it to work with a custom Node.js module loader.

I've read about similar issues with Webpack, where you can use the node-loader package to load Node.js modules, but I'm not sure how to achieve the same result with ESBuild in a serverless environment.

Has anyone successfully configured ESBuild to work with a custom Node.js module loader to resolve .node files in a serverless context? Any guidance or examples would be greatly appreciated. Thanks!

5
  • did you find a solution? I am facing the same issue Commented Jan 18, 2024 at 6:40
  • @Dhruvgarg no, I'm still waiting for their official release to handle it. I have, however went back to WebPack Commented Feb 13, 2024 at 7:13
  • I resolved the issue, by using a lambda layer Commented Feb 13, 2024 at 7:22
  • @Dhruvgarg nice. Can you post an answer here and I'll try it. Commented Feb 13, 2024 at 7:46
  • I have added it. I have tried to add a detailed answer, let me know if something is not clear. Commented Feb 13, 2024 at 11:26

1 Answer 1

0

I solved this issue by using lambda layers. I was trying to package a platform-specific library (mongodb-zstd).

you can follow these steps:

  • create a new node project
  • add the package that you want to upload as lambda layer in package.json
{
    "name": "nodejs",
    "version": "1.0.0",
    "main": "index.js",
    "license": "MIT",
    "dependencies": {
        "@mongodb-js/zstd": "^1.2.0",
        "@mongodb-js/zstd-linux-arm64-gnu": "1.2.0"
    }
}
  • zip the project including node_modules
  • upload zip as a lambda layer from AWS console: Lambda -> Additional Resources -> layers -> create layer

Now in your serverless file, you can reference the lambda layer:

functions: {
        hello: {
            handler: 'handlers.hello',
            timeout: 30,
            layers: [`arn:aws:lambda:region:\${self:custom.accountId.\${self:custom.stage}}:layer:mongo-zstd`],
        }
    }

references:

https://docs.aws.amazon.com/lambda/latest/dg/chapter-layers.html https://www.serverless.com/framework/docs/providers/aws/guide/layers

Sign up to request clarification or add additional context in comments.

Comments

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.