Error: Cannot find module 'unit-http/loader' #1316
-
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:
And the log shows:
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 33 replies
-
Attempt to execute the npm command or add a dependency
|
Beta Was this translation helpful? Give feedback.
-
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:
|
Beta Was this translation helpful? Give feedback.
-
Check whether the |
Beta Was this translation helpful? Give feedback.
-
Is there anything interesting in the Unit log when it fails to load? |
Beta Was this translation helpful? Give feedback.
-
... and that determination is yet to be made... |
Beta Was this translation helpful? Give feedback.
-
OK, so I just tried this on RHEL 9 (it's what I had to hand without messing with my main Fedora workstation, using our packages, rather than doing it all from source as I would normally do...), following the instructions from here & here tl;dr It Works! This is what I did... # cat >/etc/yum.repos.d/unit.repo
[unit]
name=unit repo
baseurl=https://packages.nginx.org/unit/rhel/$releasever/$basearch/
gpgcheck=0
enabled=1
# dnf install unit unit-devel
# systemctl start unit
# dnf install npm
# npm install -g --unsafe-perm unit-http
added 1 package, and audited 2 packages in 9s
found 0 vulnerabilities
npm notice
npm notice New major version of npm available! 8.19.4 -> 10.8.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.1
npm notice Run npm install -g [email protected] to update!
npm notice
# find /usr -name "*unit-http*" # Just to check!
/usr/local/lib/node_modules/unit-http
/usr/local/lib/node_modules/unit-http/build/unit-http.target.mk
/usr/local/lib/node_modules/unit-http/build/Release/obj.target/unit-http
/usr/local/lib/node_modules/unit-http/build/Release/obj.target/unit-http.node
/usr/local/lib/node_modules/unit-http/build/Release/.deps/Release/obj.target/unit-http
/usr/local/lib/node_modules/unit-http/build/Release/.deps/Release/obj.target/unit-http.node.d
/usr/local/lib/node_modules/unit-http/build/Release/.deps/Release/unit-http.node.d
/usr/local/lib/node_modules/unit-http/build/Release/unit-http.node
$ pwd
/home/andrew
$ mkdir node-app
$ cd node-app/
$ npm install express --save
added 64 packages, and audited 65 packages in 5s
12 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
npm notice
npm notice New major version of npm available! 8.19.4 -> 10.8.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.1
npm notice Run npm install -g [email protected] to update!
npm notice
# npm link unit-http # Yes, this needs to be run as root, yes, it's all pretty terrible!
up to date, audited 67 packages in 2s
12 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help init` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (app)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to /home/andrew/node-app/package.json:
{
"dependencies": {
"express": "^4.19.2"
},
"name": "app",
"version": "1.0.0",
"main": "index.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": ""
}
Is this OK? (yes) y
$ cat >index.js
#!/usr/bin/env node
const http = require('http')
const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello, Express on Unit!'))
http.createServer(app).listen()
$ chmod +x index.js
$ chmod 701 /home/andrew/
$ chmod 701 ../node-app/
$ cat >unitcfg.json
{
"listeners": {
"[::1]:8080": {
"pass": "applications/express"
}
},
"applications": {
"express": {
"type": "external",
"working_directory": "/home/andrew/node-app/",
"executable": "/usr/bin/env",
"arguments": [
"node",
"--loader",
"unit-http/loader.mjs",
"--require",
"unit-http/loader",
"index.js"
]
}
}
}
# curl -X PUT --data-binary @/home/andrew/node-app/unitcfg.json --unix-socket /run/unit/control.sock http://localhost/config/
{
"success": "Reconfiguration done."
}
$ curl localhost:8080
Hello, Express on Unit! |
Beta Was this translation helpful? Give feedback.
@ac000 -
$ chmod 701 /home/carlos
seems to have worked too...?!? (i.e. without requiring "user": "root" in the config)config.json