vandium-io/vandium-node

@hapi not included when deploying aws depedency layer

Opened this issue · 0 comments

So, I've developed an AWS dependency layer. I included vandium as a dependency in the layer. When I deploy the layer and try to use it from an lambda function I get the following error:

"errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module '@hapi/joi'\nRequire stack:\n- /opt/node_modules/vandium/lib/validation/joi_provider.js\n- /opt/node_modules/vandium/lib/validation/validation_provider.js\n-

Here is the package.json from the dependency layer:

{ "dependencies": { "aws-sdk": "^2.842.0", "pg": "^8.5.1", "vandium": "^6.1.0" }, "devDependencies": {} }

I included the NODE_PATH environment variable in the serverless.yml:
environment: NODE_PATH: './:/opt/node_modules'

To run locally I included the following script in the root package.json:

"offline": "export NODE_PATH=\"${PWD}/src/layers/<mylayer>/node_modules\" && serverless offline",

What looks weird to me is that the node_modules folder of the layer has the @Hapi folder. But when I package it, it is not included. Works fine locally. Doesn't work when I deploy.

As a workaround I included this in the serverless.yml:
package: excludeDevDependencies: false

When including dev dependencies, the packaged layer does include the @Hapi node_module and works fine when I deploy.

Is this normal behavior?