New `install` command added to `netlify-lambda` v1.6.0

if you are deploying your functions as folders with node_modules in them, as often happens with functions scaffolded via Netlify Dev, one common gotcha is the need to also write bash scripts to cd into those function folders and install the dependencies, or they understandably won’t exist when you try to run them, causing errors like these:

12:06:27 PM: Prepping functions with zip-it-and-ship-it 0.3.1
12:06:27 PM: Error: Could not find "form-data" module in file: /multipart-form-validation/multipart-form-validation.js.
12:06:27 PM: Please ensure "form-data" is installed in the project.
12:06:27 PM: Error prepping functions
12:06:27 PM: Error running command: Build script returned non-zero exit code: 1
12:06:27 PM: Failing build: Failed to build site
12:06:27 PM: failed during stage 'building site': Build script returned non-zero exit code: 1
12:06:28 PM: Finished processing build request in 1m12.55913707s

Our current buildbot doesn’t install function folder dependencies for you, so the solution up til now has been to write your own scripts.

We aim to make it easier with netlify-lambda install. This is a simple CLI command that you can add in TWO lines of package.json to make the problem go away.

// package.json
{
   "dependencies": {
       "netlify-lambda": "^1.6.0"
   },
   "scripts": {
       "postinstall": "netlify-lambda install"
   },
}

Happy coding!

1 Like

Thanks for this command. Nice to have.

I did add a PR to allow the root package.json of the targeted directory. Hope it makes sense.

2 Likes