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

Module did not self-register #1603

Closed
tinchoz49 opened this issue Oct 26, 2022 · 2 comments
Closed

Module did not self-register #1603

tinchoz49 opened this issue Oct 26, 2022 · 2 comments
Labels

Comments

@tinchoz49
Copy link

Bug Report

Hey everyone! 👋!

Current Behavior

I was trying to use the sharp module in my project and at the first run of the lambda handler everything works but after the lambda is cleanup (for idle timeout) I try to execute the handler again and I get the error:

Something went wrong installing the "sharp" module
  
  Module did not self-register: '/home/.../project-app/node_modules/sharp/build/Release/sharp-linux-x64.node'.
  
  Possible solutions:
  - Using worker threads? See https://sharp.pixelplumbing.com/install#worker-threads
  - Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
  - Install for the current linux-x64 runtime: "npm install --platform=linux --arch=x64 sharp"
  - Consult the installation documentation: https://sharp.pixelplumbing.com/install

Sample Code

  • file: serverless.yml
service: test-sharp
frameworkVersion: '3'

plugins:
  - serverless-offline

provider:
  name: aws
  runtime: nodejs16.x
  lambdaHashingVersion: 20201221
  memorySize: 192
  timeout: 30
  stage: production
  region: eu-west-1

custom:
  serverless-offline:
    noPrependStageInUrl: true
    # useInProcess: true

functions:
  app:
    handler: handler.handler
    events:
      - http:
          method: GET
          path: /
  • file: handler.js
const sharp = require('sharp')

module.exports.handler = async (event, context) => {
  return {
    body: 'hello'
  }
};

Expected behavior/code

The lambda handler should keep working after the cleanup.

Environment

  • serverless version: 3.23.0
  • serverless-offline version: 11.1.3
  • node.js version: [e.g. v16.15.1]
  • OS: Manjaro Linux

Possible Solution

Based on this: https://sharp.pixelplumbing.com/install#worker-threads

I try to load the library in the main thread, basically I went to the node_modules/serverless-offline module and I load the sharp module in the index.js file and it works

So my purpose is to have a new configuration option to define shared modules that need to be loaded in the main thread. Something like:

custom:
  serverless-offline:
    sharedModules: 
      - sharp
      - ...
@dnalborczyk
Copy link
Collaborator

thank you for filing the issue @tinchoz49

I'm no very familiar with native modules running in worker threads, but it seems to me that that scenario can be supported. you could file a bug with the native plugin and ask if worker threads support could be added.

https://nodejs.org/dist/latest-v19.x/docs/api/addons.html#worker-support

In order to be loaded from multiple Node.js environments, such as a main thread and a Worker thread, an add-on needs to either:

Be an Node-API addon, or
Be declared as context-aware using NODE_MODULE_INIT() as described above

in the meantime, you should be able to run your scenario in process (flag: --useInProcess), which does not use worker threads, but it also does not support handler reloading for development.

@dnalborczyk
Copy link
Collaborator

TODO: we should add this to the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants