I have been trying to add lambda functions to my site, but am encountering some issues that I do not know how to resolve as I have not worked with these types of functions before. I followed this reference to set up my functions. Inside a folder titled src
I have one api.js
file with two post routes.
When I deploy my site, it fails with the following:
3:18:44 PM: ────────────────────────────────────────────────────────────────
3:18:44 PM: Netlify Build
3:18:44 PM: ────────────────────────────────────────────────────────────────
3:18:44 PM:
3:18:44 PM: ❯ Version
3:18:44 PM: @netlify/build 27.4.2
3:18:44 PM:
3:18:44 PM: ❯ Flags
3:18:44 PM: baseRelDir: true
3:18:44 PM: buildId: 62d854effee651000813eb5b
3:18:44 PM: deployId: 62d854effee651000813eb5d
3:18:44 PM:
3:18:44 PM: ❯ Current directory
3:18:44 PM: /opt/build/repo
3:18:44 PM:
3:18:44 PM: ❯ Config file
3:18:44 PM: /opt/build/repo/netlify.toml
3:18:44 PM:
3:18:44 PM: ❯ Context
3:18:44 PM: production
3:18:44 PM:
3:18:44 PM: ────────────────────────────────────────────────────────────────
3:18:44 PM: 1. Build command from Netlify app
3:18:44 PM: ────────────────────────────────────────────────────────────────
3:18:44 PM:
3:18:44 PM: $ npm run build
3:18:44 PM: > thredx-adminpanel@0.1.0 build /opt/build/repo
3:18:44 PM: > netlify-lamba build src
3:18:44 PM: sh: 1: netlify-lamba: not found
3:18:44 PM: npm ERR! code ELIFECYCLE
3:18:44 PM: npm ERR! syscall spawn
3:18:44 PM: npm ERR! file sh
3:18:44 PM: npm ERR! errno ENOENT
3:18:44 PM: npm ERR! thredx-adminpanel@0.1.0 build: `netlify-lamba build src`
3:18:44 PM: npm ERR! spawn ENOENT
3:18:44 PM: npm ERR!
3:18:44 PM: npm ERR! Failed at the thredx-adminpanel@0.1.0 build script.
3:18:44 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
3:18:44 PM: npm ERR! A complete log of this run can be found in:
3:18:44 PM: npm ERR! /opt/buildhome/.npm/_logs/2022-07-20T19_18_44_412Z-debug.log
3:18:44 PM:
3:18:44 PM: ────────────────────────────────────────────────────────────────
3:18:44 PM: "build.command" failed
3:18:44 PM: ────────────────────────────────────────────────────────────────
3:18:44 PM:
3:18:44 PM: Error message
3:18:44 PM: Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
3:18:44 PM:
3:18:44 PM: Error location
3:18:44 PM: In Build command from Netlify app:
3:18:44 PM: npm run build
3:18:44 PM:
3:18:44 PM: Resolved config
3:18:44 PM: build:
3:18:44 PM: command: npm run build
3:18:44 PM: commandOrigin: ui
3:18:44 PM: publish: /opt/build/repo
3:18:44 PM: publishOrigin: default
3:18:44 PM: functionsDirectory: /opt/build/repo/functions
3:18:44 PM: Caching artifacts
3:18:44 PM: Started saving node modules
3:18:44 PM: Finished saving node modules
3:18:44 PM: Started saving build plugins
3:18:44 PM: Finished saving build plugins
3:18:44 PM: Started saving pip cache
3:18:44 PM: Finished saving pip cache
3:18:44 PM: Started saving emacs cask dependencies
3:18:44 PM: Finished saving emacs cask dependencies
3:18:44 PM: Started saving maven dependencies
3:18:44 PM: Finished saving maven dependencies
3:18:44 PM: Started saving boot dependencies
3:18:44 PM: Finished saving boot dependencies
3:18:44 PM: Started saving rust rustup cache
3:18:44 PM: Finished saving rust rustup cache
3:18:44 PM: Started saving go dependencies
3:18:44 PM: Finished saving go dependencies
3:18:44 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:18:44 PM: Creating deploy upload records
3:18:45 PM: Failing build: Failed to build site
3:18:45 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
3:18:45 PM: Finished processing build request in 26.93976249s
My build settings in Netlify are as follows:
- Base directory: Not set
- Build command: npm run build
- Publish directory: Not set
And my package.json
contains the following:
"dependencies": {
"express": "^4.18.1",
"netlify-lambda": "^2.0.15",
"qrcode": "^1.5.1",
"serverless-http": "^3.0.1",
"speakeasy": "^2.0.0"
},
"scripts": {
"start": "./node_modules/.bin/netlify-lambda serve src",
"build": "./node_modules/.bin/netlify-lamba build src"
}
Please advise.