Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Hello everyone,
I’m building a serverless cron job on DigitalOcean Functions (using Node.js 18) and I’m stuck on a persistent ReferenceError: module is not defined in ES module scope.
One of my functions (userDetails) works perfectly, but my cron job function (notifications) consistently fails with this error. The key difference is that the notifications function has a more complex dependency graph.
although the code is working fine at local enviroment just failing at do-functions
The Root Cause As I Understand It
My project is built as a modern ES Module.
The bundler (esbuild) gets confused by this chain (ESM -> CJS -> CJS) and produces a broken bundle that crashes in the strict ESM environment on DigitalOcean.
this is my folder structure src functions notifications.ts
import { notifications } from "../services/notifications.service";
export async function main(args: any) {
await notifications();
return {
statusCode: 200,
body: JSON.stringify({ message: "Job completed successfully" }),
};
}`
Project.yml
packages:
- name: pi-service
functions:
- name: cron-job-for-daily-notifications
runtime: nodejs:18
main: main
file: dist/notifications.js
triggers:
- name: run-daily
sourceType: scheduler
sourceDetails:
cron: "*/5 * * * *"
My Question is how do i make it work for DO-Functions
package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"bundle": "esbuild src/functions/*.ts --bundle --platform=node --target=node18 --external:uglify-js --outdir=dist",
"start:local": "npm run build && cross-env dotenv_config_path=./env/.env.dev node -r dotenv/config dist/local-dev.js",
"deploy:prod": "npm run build && npx serverless deploy --stage prod",
"deploy": "npm run bundle && doctl serverless deploy ."
},
tsconfig.json
"target": "es2022",
"sourceMap": true,
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./dist",
"rootDir": "src",
"strict": true,
"esModuleInterop": true,
"baseUrl": ".",
dolphinnn
Vaishnavi Vundyala
016512ea60864da0867e5280f293de
Peter Monadjemi
devjk1
fc9acbfbc3124cbf8df28a1c5c5cdb
ab871885551143798f41908c709271
gouskova
Saivion Services
Marin
182d09356ab94d3893ddfaca4f0270
Draco Stone