First it failed because of ’ error:0308010C:digital envelope routines::unsupported on NodeJS’, but after much googling I was able to fix this by adding --openssl-legacy-provider to NODE_OPTIONS
But now it barfs with “Critical dependency: the request of a dependency is an expression
8:03:04 PM: @ …/node_modules/express/lib/application.js
8:03:04 PM: @ …/node_modules/express/lib/express.js
8:03:04 PM: @ …/node_modules/express/index.js
8:03:04 PM: @ ./api.js”
The BUILD exits with code 2, I believe because of this warning. What to do?
Thanks so much for the reply @hrishikesh ! I blame Google ;-), that other link was ranked much higher in search.
Unfortunately, I tried the instructons at the site you provided, but the path is still bumpy and no success yet.
still had to add export NODE_OPTIONS=–openssl-legacy-provider
then build barfed because there was no build command - as per Express on Netlify | Netlify Docs I added “build”: “echo Building Functions”, to package.json
build still fails with exit code 2, though no errors shown in the log
12:45:42 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
12:45:39 PM: Netlify Build
12:45:39 PM: ────────────────────────────────────────────────────────────────
12:45:39 PM:
12:45:39 PM: ❯ Version
12:45:39 PM: @netlify/build 29.12.1
12:45:39 PM:
12:45:39 PM: ❯ Flags
12:45:39 PM: baseRelDir: true
12:45:39 PM: buildId: 64989950e29d410007c18398
12:45:39 PM: config: /opt/build/repo/netlify.toml
12:45:39 PM: deployId: 64989950e29d410007c1839a
12:45:39 PM: tracing:
12:45:39 PM: enabled: ‘false’
12:45:39 PM: host: 10.65.94.9
12:45:39 PM: parentSpanId: 9fea0d80cccb4aed
12:45:39 PM: traceFlags: ‘00’
12:45:39 PM: traceId: de5431bdd1dd283b8a87c6d5a59cd3fe
12:45:39 PM:
12:45:39 PM: ❯ Current directory
12:45:39 PM: /opt/build/repo
12:45:39 PM:
12:45:39 PM: ❯ Config file
12:45:39 PM: /opt/build/repo/netlify.toml
12:45:39 PM:
12:45:39 PM: ❯ Context
12:45:39 PM: production
12:45:39 PM:
12:45:39 PM: Build command from Netlify app
12:45:39 PM: ────────────────────────────────────────────────────────────────
12:45:39 PM:
12:45:39 PM: $ npm run build
12:45:39 PM: > evan_be@1.0.0 build
12:45:39 PM: > echo Building Functions
12:45:39 PM: Building Functions
12:45:39 PM:
12:45:39 PM: (build.command completed in 323ms)
12:45:39 PM:
12:45:39 PM: Functions bundling
12:45:39 PM: ────────────────────────────────────────────────────────────────
12:45:39 PM:
12:45:39 PM: Packaging Functions from functions directory:
12:45:39 PM: - api.js
12:45:39 PM:
12:45:40 PM:
12:45:40 PM: (Functions bundling completed in 492ms)
12:45:40 PM:
12:45:42 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:45:42 PM: Failing build: Failed to build site
12:45:42 PM: Finished processing build request in 20.45
Thanks for the reply @SamO ! As you can tell, I’m completely new to nodeJS, just trying to get ‘hello world’ going. I had already taken a look a that doc, I didn’t find anything that I was doing ‘off’, but may have missed something.
Anyways, here’s my package.json
{
“name”: “evan_be”,
“version”: “1.0.0”,
“description”: “”,
“main”: “index.js”,
“scripts”: {
“build”: “echo Building Functions”,
“test”: “echo "Error: no test specified" && exit 1”
},
“keywords”: ,
“author”: “”,
“license”: “ISC”,
“dependencies”: {
“@netlify/functions”: “^1.6.0”,
“@types/express”: “^4.17.17”,
“express”: “^4.18.2”,
“netlify-lambda”: “^2.0.16”,
“serverless-http”: “^3.2.0”
}
}
and here’s netlify.toml
[functions]
external_node_modules = [“express”]
node_bundler = “esbuild”
[[redirects]]
force = true
from = “/api/*”
status = 200
to = “/.netlify/functions/api/:splat”
On Netlify, my “Build & Deploy” settings are all the defaults.
My “environment variables” set one thing:
NODE_OPTIONS=–openssl-legacy-provider
Not sure why unless you’re still using webpack somewhere. Your package.json still had netlify-lambda, so most likely it came from there.
When following the documentation, please do as per the documentation if you don’t want to get errors. I forked your repo, made changes according to the documentation and the site worked fine without any config: f-95268.netlify.app/api/hello