Cannot deploy a node js express with openai on render.. getting error of AbortController not defined

Good day Everyone, Please I am stuck here. I already deployed without openai integration but once incorporated it to my code my render deployed failed. try confirming by deploying without it and it worked but once i integrate it does not worked again. It only worked on the local server.
this is the error: ReferenceError: AbortController is not defined
Aug 24 10:22:05 AM at Object. (/opt/render/project/src/node_modules/openai/_shims/agent.node.js:21:19)
Aug 24 10:22:05 AM at Module._compile (internal/modules/cjs/loader.js:1068:30)
Aug 24 10:22:05 AM at Object.Module._extensions…js (internal/modules/cjs/loader.js:1097:10)
Aug 24 10:22:05 AM at Module.load (internal/modules/cjs/loader.js:933:32)
Aug 24 10:22:05 AM at Function.Module._load (internal/modules/cjs/loader.js:774:14)
Aug 24 10:22:05 AM at Module.require (internal/modules/cjs/loader.js:957:19)
Aug 24 10:22:05 AM at require (internal/modules/cjs/helpers.js:88:18)
Aug 24 10:22:05 AM at Object. (/opt/render/project/src/node_modules/openai/core.js:62:17)
Aug 24 10:22:05 AM at Module._compile (internal/modules/cjs/loader.js:1068:30)
Aug 24 10:22:05 AM at Object.Module._extensions…js (internal/modules/cjs/loader.js:1097:10)

1 Like

Hi and welcome to the developer forum!

What version of NodeJS are you running? That error is typically associated with running an old version.

Thanks for the swift response. Using Node version 14.17.0 (default)

I’m fairly sure you need 16.6 or above for it to work.

should the env be in this format: NODE_VERSION: 16.6.0

It is working now, Thank you very much

3 Likes

Good day, and sorry for asking here despite the main question is already answered and resolved but as I have the same issue despite trying to update Node version , I kept having the same error
I have the same problem but I am running node v18.12.1
the only difference that I am running nodemon server instead
and here the package.json of different installed packages:
“dependencies”: {
“cors”: “^2.8.5”,
“dotenv”: “^16.0.3”,
“express”: “^4.18.2”,
“nodemon”: “^3.0.1”,
“node”: “^18.12.1”,
“openai”: “^4.3.0”
}

I tried to deploy in different servers as render or gcloud app engine, always having the same trouble

Hi, please create a new thread and list the exact error message and your server environment details.

1 Like

I have the same problem when I need to deploy my app to render. How did you solve this? I have this message:

Sep 5 02:51:13 PM  ReferenceError: AbortController is not defined
Sep 5 02:51:13 PM      at file:///opt/render/project/src/server/node_modules/openai/_shims/agent.node.mjs:10:19
Sep 5 02:51:13 PM      at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
Sep 5 02:51:13 PM      at async Loader.import (internal/modules/esm/loader.js:177:24)
Sep 5 02:51:13 PM      at async Object.loadESM (internal/process/esm_loader.js:68:5)
Sep 5 02:51:13 PM  [nodemon] app crashed - waiting for file changes before starting...
Sep 5 02:52:18 PM  ==> No open HTTP ports detected
Sep 5 02:52:18 PM  ==> https://render.com/docs/web-services#host-and-port-configuration
Sep 5 03:08:18 PM  ==> Using Node version 14.17.0 (default)
Sep 5 03:08:18 PM  ==> Docs on specifying a Node version: https://render.com/docs/node-version
Sep 5 03:08:18 PM  ==> Starting service with 'npm run start'
Sep 5 03:08:21 PM  
Sep 5 03:08:21 PM  > server@1.0.0 start /opt/render/project/src/server
Sep 5 03:08:21 PM  > nodemon index
Sep 5 03:08:21 PM  
Sep 5 03:08:23 PM  [nodemon] 3.0.1
Sep 5 03:08:23 PM  [nodemon] to restart at any time, enter `rs`
Sep 5 03:08:23 PM  [nodemon] watching path(s): *.*
Sep 5 03:08:23 PM  [nodemon] watching extensions: js,mjs,cjs,json
Sep 5 03:08:23 PM  [nodemon] starting `node index.js`
Sep 5 03:08:31 PM  file:///opt/render/project/src/server/node_modules/openai/_shims/agent.node.mjs:10
Sep 5 03:08:31 PM    AbortController = AbortControllerPolyfill;
Sep 5 03:08:31 PM                    ^
Sep 5 03:08:31 PM  
Sep 5 03:08:31 PM  ReferenceError: AbortController is not defined
Sep 5 03:08:31 PM      at file:///opt/render/project/src/server/node_modules/openai/_shims/agent.node.mjs:10:19
Sep 5 03:08:31 PM      at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
Sep 5 03:08:31 PM      at async Loader.import (internal/modules/esm/loader.js:177:24)
Sep 5 03:08:31 PM      at async Object.loadESM (internal/process/esm_loader.js:68:5)
Sep 5 03:08:31 PM  [nodemon] app crashed - waiting for file changes before starting...
1 Like

I just figured it out - if anyone is also still encountering this after you’ve updated node to 16.6 or greater - you have to change the environment variable in render as well, and theres a few ways to do that. Render automatically runs 14.4 by default so you have to tell it run a more recent version

The easiest is just specifying NODE_VARIABLE in the env variables within render and putting whatever version you’re using. here is the documentation

4 Likes