node.jsubuntunpmchrootjail-shell

Setup nodejs and npm within Jailkit


I am using jailkit on my server, and I want to add support for nodejs and npm inside the chrooted environment. I don't know if I'm missing some directory that I need to link into my jail, or some lib or binary, but I'm quite lost. I added the following to jk_init.ini:

[node]
comment = NodeJS
executables = /usr/bin/npm, /usr/bin/node, /usr/bin/nodejs
directories = /usr/local/lib/node_modules

If I run npm ls from my root user, it runs fine. If I try to run it from my jailed environment, I get this error:

npm ERR! Linux 3.16.0-28-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "ls"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! code MODULE_NOT_FOUND

npm ERR! Cannot find module 'ansi'
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /web/npm-debug.log

The log files has this:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'ls' ]
2 info using npm@3.5.2
3 info using node@v4.2.6
4 verbose stack Error: Cannot find module 'ansi'
4 verbose stack     at Function.Module._resolveFilename (module.js:326:15)
4 verbose stack     at Function.Module._load (module.js:277:25)
4 verbose stack     at Module.require (module.js:354:17)
4 verbose stack     at require (internal/module.js:12:17)
4 verbose stack     at Object.<anonymous> (/usr/share/npm/lib/ls.js:15:13)
4 verbose stack     at Module._compile (module.js:410:26)
4 verbose stack     at Object.Module._extensions..js (module.js:417:10)
4 verbose stack     at Module.load (module.js:344:32)
4 verbose stack     at Function.Module._load (module.js:301:12)
4 verbose stack     at Module.require (module.js:354:17)
5 verbose cwd /web
6 error Linux 3.16.0-28-generic
7 error argv "/usr/bin/nodejs" "/usr/bin/npm" "ls"
8 error node v4.2.6
9 error npm  v3.5.2
10 error code MODULE_NOT_FOUND
11 error Cannot find module 'ansi'
12 error If you need help, you may report this error at:
12 error     <https://github.com/npm/npm/issues>
13 verbose exit [ 1, true ]

I'm running the latest version of Ubuntu with ISPConfig


Solution

  • Had the problem also today, fixed it by changing

    directories = /usr/local/lib/node_modules 
    

    to

    directories = /usr/lib/node_modules
    

    Debian Jessie, also on ISPConfig.

    Remeber to trigger

    jk_init -c /etc/jailkit/jk_init.ini -f -k -j /var/www/clients/clientX/web62 node