You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
nodejs unit-http misses options in createServer function #1043
I tried to run strapi inside nginx unit. The startup of strapi doesn't work because of the following error:
TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received an instance of Object
at checkListener (node:events:270:3)
at _addListener (node:events:550:3)
at Server.addListener (node:events:609:10)
at new Server (/usr/local/lib/node_modules/unit-http/http_server.js:426:14)
at Object.createServer (/usr/local/lib/node_modules/unit-http/http.js:15:12)
at Module.createHTTPServer (/var/www/node_modules/@strapi/strapi/dist/services/server/http-server.js:16:40)
at Module.createServer (/var/www/node_modules/@strapi/strapi/dist/services/server/index.js:26:35)
at new Strapi (/var/www/node_modules/@strapi/strapi/dist/Strapi.js:130:27)
at initFn (/var/www/node_modules/@strapi/strapi/dist/Strapi.js:466:18)
at Object.<anonymous> (/var/www/index.js:2:1) {
code: 'ERR_INVALID_ARG_TYPE'
}
Strapi uses options with the http.createServer function as seen here in the source code. The node signature of the createServer function looks like this: http.createServer([options][, requestListener]). Looking at the http module inside the unit-http package the createServer function is missing the options argument.
Can this be solved somehow? How could strapi be started otherwise within nginx unit?
I could create a fix by using patch-package with the following steps:
Install unit-http and patch-package as npm dependencies: npm i unit-http patch-package --save
Add "postinstall": "patch-package" under "scripts" inside package.json
Edit the http.js file inside node_modules/unit-http by adding options as the first argument to the createServer function:
function createServer (options, requestHandler) {
return new Server(requestHandler);
}
Apply the patch: npx patch-package unit-http
As a current workaround this is ok. Although I think this might not be a sustainable approach. The options could be ignored in the case of our strapi deployment.
Looks like the options argument was added in Node.js v9.6.0 (2018-02-22) / v8.12.0 (2018-09-11) in nodejs/node#15752 and we missed it when implementing our shim for http.createServer.
We should fix this in Unit, but the patch-package workaround should be fine for your use case until we can get a release out with a proper fix.
Activity
stefanhuber commentedon Jan 4, 2024
I could create a fix by using
patch-packagewith the following steps:unit-httpandpatch-packageas npm dependencies:npm i unit-http patch-package --save"postinstall": "patch-package"under"scripts"insidepackage.jsonhttp.jsfile insidenode_modules/unit-httpby addingoptionsas the first argument to thecreateServerfunction:npx patch-package unit-httpAs a current workaround this is ok. Although I think this might not be a sustainable approach. The
optionscould be ignored in the case of our strapi deployment.callahad commentedon Jan 5, 2024
Looks like the
optionsargument was added in Node.js v9.6.0 (2018-02-22) / v8.12.0 (2018-09-11) in nodejs/node#15752 and we missed it when implementing our shim forhttp.createServer.We should fix this in Unit, but the patch-package workaround should be fine for your use case until we can get a release out with a proper fix.
Take options as well as requestListener
Take options as well as requestListener
Take options as well as requestListener
Take options as well as requestListener
Take options as well as requestListener
Take options as well as requestListener
Take options as well as requestListener
Take options as well as requestListener
fix: Take options as well as requestListener (#1091)
fix: Take options as well as requestListener (#1091)
fix: Take options as well as requestListener (nginx#1091)