I'm trying to add <leveldb> as a dependency for a ...
# help
k
I'm trying to add leveldb as a dependency for a lambda and running into the following error when handling a request in live dev mode:
Copy code
No native build was found for platform=darwin arch=x64 runtime=node abi=72 uv=1 libc=glibc node=12.22.6

at Function.load.path (.../node_modules/node-gyp-build/index.js:59:9) ...
There is a binary dependency,
leveldown
which I've tried adding to bundle.nodeModules without success. I've confirmed that locally the darwin-x64 binary is present (in node_modules). I've also confirmed that the issue does not occur when deploying to the lambda to aws. Any suggestions?
f
Hey @Kelly Davis, can I see what your
package.json
looks like and how you are defining the function?
k
Copy code
const fun = new sst.Function(this, 'router', {
      runtime: 'nodejs14.x',
      handler: '../js/mylambda/src/index.koaHandler',
      bundle: {
        externalModules: ['aws-sdk'],
        nodeModules: ['leveldown'],
      },
      timeout: 300,
      environment: {
        STAGE: stage,
        BASE_HOSTNAME: process.env.BASE_HOSTNAME,
      },
      vpc,
      vpcSubnets: {
        subnets: [subnet1, subnet2]
      },
    })
Copy code
{
  ...
  "dependencies": {
    "@aws-sdk/client-dynamodb": "^3.12.0",
    "@koa/cors": "^3.1.0",
    "axios": ">=0.21.2",
    "glob-promise": "^4.2.1",
    "koa": "^2.13.1",
    "koa-bodyparser": "^4.3.0",
    "koa-json": "^2.0.2",
    "koa-router": "^10.0.0",
    "level": "^7.0.0",
    "serverless-http": "^2.7.0",
  },
  "devDependencies": {
    "@babel/preset-typescript": "^7.12.7",
    "@shopify/jest-koa-mocks": "^2.3.3",
    "@types/aws-lambda": "^8.10.71",
    "@types/body-parser": "^1.19.0",
    "@types/cookie-parser": "^1.4.2",
    "@types/cors": "^2.8.8",
    "@types/express": "^4.17.8",
    "@types/jest": "^26.0.20",
    "@types/koa": "^2.13.1",
    "@types/koa-json": "^2.0.18",
    "@types/koa-router": "^7.4.1",
    "@types/koa__cors": "^3.0.2",
    "@types/level": "^6.0.0",
    "@types/node": "^14.14.5",
    "aws-sdk": "^2.635.0",
    "aws-sdk-mock": "^5.1.0",
    "jest": "26.6.0",
    "jest-in-case": "^1.0.2",
    "ts-jest": "^26.5.0",
    "ts-node": "^9.1.1",
    "tsup": "^3.7.1",
    "typescript": "^4.1.3"
  }
}