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

Error: Cannot find module 'unit-http/loader' #1313

Closed stacy-rendall closed 1 week ago

stacy-rendall commented 2 weeks ago

I am receiving this error trying to use Unit with Node.js

To repro I've tested completely clean from scratch in a fresh Debian live image (debian-live-12.5.0-amd64-lxqt.iso) and still get the error. Steps:

On attempting to put the config I get the following response:

{
    "error": "Failed to apply new configuration."
}

And the log shows:

2024/06/12 16:37:58 [info] 5052#5052 "express" prototype started
2024/06/12 16:37:58 [info] 5053#5053 "express" application started
node:internal/modules/cjs/loader:1148
  throw err;
  ^

Error: Cannot find module 'unit-http/loader'
Require stack:
- internal/preload
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at internalRequire (node:internal/modules/cjs/loader:176:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1563:5)
    at loadPreloadModules (node:internal/process/pre_execution:730:5)
    at setupUserModules (node:internal/process/pre_execution:206:5)
    at prepareExecution (node:internal/process/pre_execution:159:5)
    at prepareMainThreadExecution (node:internal/process/pre_execution:54:10)
    at node:internal/main/run_main_module:11:19 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'internal/preload' ]
}

Node.js v20.14.0
2024/06/12 16:37:58 [notice] 5052#5052 app process 5053 exited with code 1
2024/06/12 16:37:58 [warn] 1199#1199 failed to start application "express"
2024/06/12 16:37:58 [alert] 1199#1199 failed to apply new conf
2024/06/12 16:37:58 [notice] 1195#1195 process 5052 exited with code 0
dbit-xia commented 1 week ago

Attempt to execute the npm command or add a dependency

npm install unit-http 
stacy-rendall commented 1 week ago

That executes successfully:

user@debian:~/repos/expressunit$ npm install unit-http 

changed 1 package, and audited 66 packages in 985ms

12 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

package.json

{
  "dependencies": {
    "express": "^4.19.2",
    "unit-http": "^1.32.1"
  },
  "name": "expressunit",
  "version": "1.0.0",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}

I attempted a few different combinations on my Debian 12 OS (not the live OS as above, which ws just for a clean repro), all of which still give the same error as shown in my first post, when applying the config:

  1. without linking at all:
    1. take back app ownership as user
    2. remove global unit-http install: sudo npm -g uninstall unit-http
    3. rm -rf node_modules package-lock.json
    4. npm install express unit-http
    5. chown app unit:unit
    6. apply config
  2. global install, local install, no link:
    1. redo sudo npm install -g --unsafe-perm unit-http
    2. take back app ownership as user
    3. rm -rf node_modules package-lock.json
    4. npm install express unit-http
    5. chown app unit:unit
    6. apply config
  3. global install, local install, then link:
    1. with unit-http still available as global dependency
    2. take back app ownership as user
    3. rm -rf node_modules package-lock.json
    4. npm install express unit-http
    5. sudo npm link unit-http
    6. chown app unit:unit
    7. apply config
  4. global install, link, then local install:
    1. with unit-http still available as global dependency
    2. take back app ownership as user
    3. sudo npm link unit-http
    4. npm install express unit-http
    5. chown app unit:unit
    6. apply config
dbit-xia commented 1 week ago

Check whether the working_directory configured in the unit is the application root directory? Or enter the container and execute the command node -e 'require('unit-http/loader')'