Can't build simplest node express app

Hi all, I’m trying to deploy the very simple Node Express app described at " Express server on Netlify for free - Step by step guide" , and it’s failing.

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?

The failed build log is at Netlify App


Please refer to official docs over third-party blog posts: Express on Netlify | Netlify Docs

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.

  1. still had to add export NODE_OPTIONS=–openssl-legacy-provider
  2. 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
  3. 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:
    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


I’m seeing your build fails due to config in your most recent deploy. Can you share what your build settings look like?

Also can you take a look at this support guide as it may answer your questions:

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
external_node_modules = [“express”]
node_bundler = “esbuild”
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:

and that’s it.

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:

I’ve submitted a PR here: Fix issues by Hrishikesh-K · Pull Request #1 · kfishkin/evan_be (

wow, what great support, thanks!!
I’m still not sure what it was I did wrong, but having a working example is what I needed. Thanks again!