nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.25k stars 320 forks source link

Node.js: Unable to run due to Server this.on is not a function #1328

Closed willnode closed 2 days ago

willnode commented 1 week ago

Application config

{
      "type": "external",
      "working_directory": "/home/bridge/public_html/webssh2/app",
      "executable": "/usr/bin/env",
      "stdout": "/home/bridge/logs/unit-stdout.log",
      "stderr": "/home/bridge/logs/unit-stderr.log",
      "user": "bridge",
      "group": "bridge",
      "arguments": [
        "bash",
        "-lc",
        "node --loader  unit-http/loader.mjs --require unit-http/loader app.js"
      ]
    }

Error stack

/home/bridge/public_html/webssh2/app/node_modules/unit-http/http_server.js:437
        this.on('request', requestListener);
             ^

TypeError: this.on is not a function
    at Object.Server (/home/bridge/public_html/webssh2/app/node_modules/unit-http/http_server.js:437:14)
    at Object.<anonymous> (/home/bridge/public_html/webssh2/app/server/app.js:16:37)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
    at Module.load (node:internal/modules/cjs/loader:1203:32)
    at Module._load (node:internal/modules/cjs/loader:1019:12)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at Module.require (/home/bridge/public_html/webssh2/app/node_modules/unit-http/loader.js:24:29)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (/home/bridge/public_html/webssh2/app/index.js:13:20)

Code:

const app = express();
const server = require('http').Server(app);

Seen from https://github.com/billchurch/webssh2/blob/main/app/server/app.js

Versions:

$ node -v
v18.20.2
$ unitd --version
unit version: 1.32.1
configured as ./configure --prefix=/usr --statedir=/var/lib/unit --control=unix:/var/run/unit/control.sock --runstatedir=/var/run --pid=/var/run/unit/unit.pid --logdir=/var/log --log=/var/log/unit/unit.log --tmpdir=/var/tmp --user=unit --group=unit --tests --openssl --njs --modulesdir=/usr/lib64/unit/modules --libdir=/usr/lib64 --cc-opt='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC' --ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
willnode commented 1 week ago

Ahh right this is caused by lack of new keyword, or it should use createServer instead!

javorszky commented 2 days ago

@willnode it seems like this is not a unit bug. Is there anything else you need help with, or can we close this for now?

willnode commented 2 days ago

Yeah, this can be closed. Just pointing out for future users having this problem.

javorszky commented 2 days ago

Excellent, thank you! Hope it's going to be useful for them :)