Site 'cannot find module ejs' despite it working in local dev

I’m building a site that fetches data from a googlesheets with Express and Googlecloud api library. I used netlify lambda’s serverless function to load the data using express, an ejs file called mainPage is then rendered with the data appended.

The code works locally when I tried using the netlify CLI, however when it is deployed, an error occurs as seen in its current deploy at the website link . GitHub repo, this is my repo and I publish from the dist directory. The build command is currently not set to anything in the netlify ui since using ‘npm run build’ returns an error.

this is the build log:
6:22:49 PM: Waiting for other deploys from your team to complete. Check the queue: Netlify App
6:23:00 PM: build-image version: 4b067841aaa59ef71931d3505b98c2bc3e63f36f (focal)
6:23:00 PM: buildbot version: 4b067841aaa59ef71931d3505b98c2bc3e63f36f
6:23:00 PM: Fetching cached dependencies
6:23:00 PM: Starting to download cache of 83.1MB
6:23:01 PM: Finished downloading cache in 712ms
6:23:01 PM: Starting to extract cache
6:23:02 PM: Finished extracting cache in 617ms
6:23:02 PM: Finished fetching cache in 1.398s
6:23:02 PM: Starting to prepare the repo for build
6:23:02 PM: Preparing Git Reference refs/heads/master
6:23:03 PM: Parsing package.json dependencies
6:23:04 PM: Starting to install dependencies
6:23:04 PM: Python version set to 3.8
6:23:04 PM: Attempting Ruby version 2.7.2, read from environment
6:23:05 PM: Using Ruby version 2.7.2
6:23:05 PM: Started restoring cached go cache
6:23:05 PM: Finished restoring cached go cache
6:23:05 PM: go version go1.19.9 linux/amd64
6:23:06 PM: Using PHP version 8.0
6:23:07 PM: Started restoring cached Node.js version
6:23:07 PM: Finished restoring cached Node.js version
6:23:08 PM: v16.20.0 is already installed.
6:23:08 PM: Now using node v16.20.0 (npm v8.19.4)
6:23:08 PM: Enabling Node.js Corepack
6:23:08 PM: Started restoring cached build plugins
6:23:08 PM: Finished restoring cached build plugins
6:23:08 PM: Started restoring cached corepack dependencies
6:23:08 PM: Finished restoring cached corepack dependencies
6:23:08 PM: No npm workspaces detected
6:23:08 PM: Started restoring cached node modules
6:23:08 PM: Finished restoring cached node modules
6:23:08 PM: Installing npm packages using npm version 8.19.4
6:23:10 PM: up to date, audited 674 packages in 1s
6:23:10 PM: 40 packages are looking for funding
6:23:10 PM: run npm fund for details
6:23:10 PM: 5 high severity vulnerabilities
6:23:10 PM: To address all issues, run:
6:23:10 PM: npm audit fix
6:23:10 PM: Run npm audit for details.
6:23:10 PM: npm packages installed
6:23:10 PM: Install dependencies script success
6:23:10 PM: Starting build script
6:23:11 PM: Detected 0 framework(s)
6:23:11 PM: Section completed: initializing
6:23:12 PM: ​
6:23:12 PM: Netlify Build
6:23:12 PM: ────────────────────────────────────────────────────────────────
6:23:12 PM: ​
6:23:12 PM: ❯ Version
6:23:12 PM: @netlify/build 29.11.5
6:23:12 PM: ​
6:23:12 PM: ❯ Flags
6:23:12 PM: baseRelDir: true
6:23:12 PM: buildId: 6469ff0987699f00080d1cfb
6:23:12 PM: deployId: 6469ff0987699f00080d1cfd
6:23:12 PM: ​
6:23:12 PM: ❯ Current directory
6:23:12 PM: /opt/build/repo
6:23:12 PM: ​
6:23:12 PM: ❯ Config file
6:23:12 PM: /opt/build/repo/netlify.toml
6:23:12 PM: ​
6:23:12 PM: ❯ Context
6:23:12 PM: production
6:23:12 PM: ​
6:23:12 PM: Functions bundling
6:23:12 PM: ────────────────────────────────────────────────────────────────
6:23:12 PM: ​
6:23:12 PM: Packaging Functions from functions directory:
6:23:12 PM: - api.js
6:23:12 PM: ​
6:23:15 PM: ​
6:23:15 PM: (Functions bundling completed in 2.3s)
6:23:15 PM: ​
6:23:15 PM: Deploy site
6:23:15 PM: ────────────────────────────────────────────────────────────────
6:23:15 PM: ​
6:23:15 PM: Starting to deploy site from ‘dist’
6:23:15 PM: Calculating files to upload
6:23:15 PM: 0 new files to upload
6:23:15 PM: 1 new functions to upload
6:23:22 PM: Section completed: deploying
6:23:22 PM: Site deploy was successfully initiated
6:23:22 PM: ​
6:23:22 PM: Starting post processing
6:23:22 PM: (Deploy site completed in 7.4s)
6:23:22 PM: ​
6:23:22 PM: Netlify Build Complete
6:23:22 PM: Skipping HTML post processing
6:23:22 PM: ────────────────────────────────────────────────────────────────
6:23:22 PM: ​
6:23:22 PM: (Netlify Build completed in 9.8s)
6:23:22 PM: Post processing - header rules
6:23:22 PM: Post processing - redirect rules
6:23:23 PM: Caching artifacts
6:23:23 PM: Started saving node modules
6:23:23 PM: Finished saving node modules
6:23:23 PM: Post processing done
6:23:23 PM: Started saving build plugins
6:23:23 PM: Finished saving build plugins
6:23:23 PM: Started saving corepack cache
6:23:23 PM: Section completed: postprocessing
6:23:23 PM: Finished saving corepack cache
6:23:23 PM: Started saving pip cache
6:23:23 PM: Finished saving pip cache
6:23:23 PM: Started saving emacs cask dependencies
6:23:23 PM: Finished saving emacs cask dependencies
6:23:23 PM: Started saving maven dependencies
6:23:23 PM: Finished saving maven dependencies
6:23:23 PM: Started saving boot dependencies
6:23:23 PM: Finished saving boot dependencies
6:23:23 PM: Site is live :sparkles:
6:23:23 PM: Started saving rust rustup cache
6:23:23 PM: Finished saving rust rustup cache
6:23:23 PM: Started saving go dependencies
6:23:23 PM: Finished saving go dependencies
6:23:23 PM: Build script success
6:23:23 PM: Section completed: building
6:23:23 PM: Uploading Cache of size 83.0MB
6:23:24 PM: Section completed: cleanup
6:23:24 PM: Finished processing build request in 23.744s

Any help on how I could get the site to work is very much appreciated…

I’d recommend trying esbuild as per the docs: Express on Netlify | Netlify Docs (refer to netlify.toml in step 4).

Thank you for the reply, I tried changing the toml content and followed the steps listed in the docs however it resulted in no effect despite the new version being automatically deployed. It still shows the same error as previous

Hiya, if you are still experiencing this problem it might be helpful to attach a link to your repo as this may likely be an issue with how your repo is config’d