Brian Thomas Brian Thomas - 6 months ago 132
Node.js Question

node and or npm issue

I am having various permission and or path issues with some npm packages, this time being deployd's dpd binary. However it still seems related to pretty much any other familiar frustrating npm path issue that i receive now and then. Its pretty much a familiar face of npm usage it seems, given my constant use of -g, and not, when installing npm packs..

So far to resolve it I tried reinstalling deployd and mongodb many times from user and globally, i have even reinstalled npm. im getting consistent package errors when running dpd. I found lots related, but none that have worked. Here is my issue when running dpd today. Any grand suggestions?

When ran from linux i the following
$ dpd
starting deployd v0.8.4...
Failed to start MongoDB (Make sure 'mongod' are in your $PATH or use dpd --mongod option. Ref: http://docs.deployd.com/docs/basics/cli.html)
bye

$ sudo dpd
starting deployd v0.8.4...
Failed to start MongoDB (Make sure 'mongod' are in your $PATH or use dpd --mongod option. Ref: http://docs.deployd.com/docs/basics/cli.html)
bye

$ dpd --mongod ./.dpd/pids
starting deployd v0.8.4...
child_process.js:1162
throw errnoException(err, 'spawn');
^
Error: spawn EACCES
at exports._errnoException (util.js:746:11)
at ChildProcess.spawn (child_process.js:1162:11)
at exports.spawn (child_process.js:995:9)
at Object.exports.restart (/usr/bin/node_modules/bin/lib/node_modules/deployd/lib/util/mongod.js:38:14)
at start (/usr/bin/node_modules/bin/lib/node_modules/deployd/bin/dpd:149:16)
at Object.<anonymous> (/usr/bin/node_modules/bin/lib/node_modules/deployd/bin/dpd:280:31)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3


even if i run it sudo i get the same error.

$ sudo dpd --mongod ./.dpd/pids
starting deployd v0.8.4...
child_process.js:1162
throw errnoException(err, 'spawn');
^
Error: spawn EACCES
at exports._errnoException (util.js:746:11)
at ChildProcess.spawn (child_process.js:1162:11)
at exports.spawn (child_process.js:995:9)
at Object.exports.restart (/usr/bin/node_modules/bin/lib/node_modules/deployd/lib/util/mongod.js:38:14)
at start (/usr/bin/node_modules/bin/lib/node_modules/deployd/bin/dpd:149:16)
at Object.<anonymous> (/usr/bin/node_modules/bin/lib/node_modules/deployd/bin/dpd:280:31)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3


When ran from windows on a samba share mapped network drive i get this

dpd > fs: missing callback Error: EPERM, open 'C:\Program Files (x86)\Deployd\node_modules\deployd\.latestversion'


what am i doing wrong here?

I cannot find this file, nor this line of code anywhere,
child_process.js:1162
throw errnoException(err, 'spawn');
when i grep for it, one reference does turn up for the line of code, that's /bin/node, and when i open it in vim, it looks encrypted... i think ill look again, and that line may be there... hmm.

ok i did find that line in node binary itself,

this.spawnfile = options.file;

var err = this._handle.spawn(options);

// Run-time errors should emit an error, not throw an exception. if (err === uv.UV_EAGAIN ||
err === uv.UV_EMFILE ||
err === uv.UV_ENFILE ||
err === uv.UV_ENOENT) {
process.nextTick(function() {
self._handle.onexit(err);
});
// There is no point in continuing when we've hit EMFILE or ENFILE
// because we won't be able to set up the stdio file descriptors.
// It's kind of silly that the de facto spec for ENOENT (the test suite)
// mandates that stdio _is_ set up, even if there is no process on the
// receiving end, but it is what it is.
if (err !== uv.UV_ENOENT) return err; } else if (err) {
// Close all opened fds on error
stdio.forEach(function(stdio) {
if (stdio.type === 'pipe') {
stdio.handle.close();
}
});

this._handle.close();
this._handle = null;
throw errnoException(err, 'spawn'); }


is this some kind of crazy permission error? i think i set at 755 to all files, and dirs when ran as user as well.. no selinux installed, might have some facls... doubt it, in this dir..

I reinstalled npm and nodejs, and didnt help. This is on an arch linux box.

Edit: yeah that's not working either for some reason, even after i resolved the other one by correcting permission issues.

$ dpd -d --mongod /usr/bin/node_modules/bin/lib/node_modules
starting deployd v0.8.4...
deployd v0.8.5 is available.

child_process.js:1162
throw errnoException(err, 'spawn');
^
Error: spawn EACCES
at exports._errnoException (util.js:746:11)
at ChildProcess.spawn (child_process.js:1162:11)
at exports.spawn (child_process.js:995:9)
at Object.exports.restart (/usr/bin/node_modules/bin/lib/node_modules/deployd/lib/util/mongod.js:38:14)
at start (/usr/bin/node_modules/bin/lib/node_modules/deployd/bin/dpd:149:16)
at Object.<anonymous> (/usr/bin/node_modules/bin/lib/node_modules/deployd/bin/dpd:280:31)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

Answer

Notice EACCESS, this means its a permission issue. The permissions of dpd needs proper access to run. Check the permissions on the dpd binary which is the potential cause for the EACCESS errors. Possibly since sudo npm -g was ran as as sudo the catch 22 may have became that since ran as sudo, the permissions werent set right somewhere on the dpd chain, possibly even the symlink itself, so you need to manually go to the binary symlink in /usr/bin/node_modules/bin/bin/pdp to /lib/node_modules/deployd/bin and reset the permissions in it.

However, deeper thinking, possibly the problem is due to the dpd installtion itself as ran from sudo, since npm may have already added in a nice error output for this this logic chain already.

Also, the permmissions of .npm in your linux user dir needs be checked, some things may have been done as root, and or sudo in there. you would want to recursively reset the permissions back to your user in there.

Resolution:


If your installing dpd or npm from sudo, or have somehow else accrued some permission issues, this is the command that will fix the permissions, and start deployd using the reference to mongodb(if necessary):

$ chown <youruser>:<yourgroup> ~/.npm -R
$ cd /lib/node_modules/deployd/bin
$ sudo chown root:yourGroup dpd
$ sudo chmod g+rwx dpd
$ dpd -d --mongod .dpd/pids/mongod
    starting deployd v0.8.4...
    deployd v0.8.5 is available.

If your running deployd from windows, you have to run the cmd prompt as admin.
If you have a mapped network drive, when you run as admin, you will not have access to this mapped network drive. The easiest solution for you at that point will be for you just to map it via dos,

c:/ #> net use x: \\hostname\\share
c:/ #> x:
x:/ #> cd ~/yourprojectdir/deploydSite
x:/yourprojectdir/deploydSite #> dpd -d

That exact setup might not work exactly for you, but it gives you the idea, to lax the permissions when you install dpd as -g or with sudo at all.

Prevention; Proper npm package $PATH usage

When do we, and when do we NOT install npm packages globally? That depends on your applications needs, and experience level.

There are times when we need to install npm packages globally i.e. sudo npm -g which adds the node modules to the /root/.node_modules and or in the upper directories of the linux file system for global availability on a root permissed/pwned $PATH, which is somewhere near /usr/bin/node_modules.

Some global times can be for instance;

1) when any of us want to add a global module to our users site project directory, in a global location, which will not need to be deployed or part of the applicatins repo (npm packs used during dev time only)

2) or when were having permission issues and just do so because of it as an attempt to fellswoop overcome permission issues (not usually a good idea ill add, and will get you into this fix in the first place)

Some non global times can also exist: i.e. When we want the npm packages to be installed NOT globally.

1) Maybe we want them available to all our users projects only, want to keep our apps clean, will use them out of ~/.npm when running our appd. Heck, the admin of the system might even only allows us such, to protect the global space of other devs. SO for example: This means we want to install npm packages NOT globally, which puts them into our ~/.npm/node_modules $PATH ideally, and does Not use the -g option.

2) Or maybe we want to deploy the modules with our app(usually for production needs, to ensure the packages will be there for the shelf-life duration of your app), so we install them in the same directory as our application so that they can become part of the repo, which again does Not use the -g option.

So, when do i install npm packages globally? It depends on the needs and requirements of your application, or development needs, see above.

- Tally up any needed paths After installation, you need to make sure you have all paths available you. You are going to need to find where all these modules are. For each module look them up, take a tally of all the directories they reside in, then cross reference that with your path

$ echo $PATH it might return something like this /usr/local/sbin:/usr/local/bin:/usr/bin/node_modules/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl

$ which node
/usr/bin/node
$ which npm
/usr/bin/npm
$ which dpd
/usr/bin/node_modules/bin/bin/dpd
$ which less
/usr/bin/less
$ which uglifyjs
/usr/bin/uglifyjs

So here we need to ensure our path has exactly the following appended to it in some way /usr/bin; /usr/bin/node_modules/bin/bin; as you can see, since this is where our package bins/modules are that we need to reference from our app or command line.

One way you can make sure those are added to your users $PATH is by editing your bashrc file.

- Edit your bashrc accordingly per your distro.. vim ~/.bashrc

NODE_MODULES=/usr/bin/bode_modules/bin/bin:/usr/bin
export PATH=<someadditionalpath-maybe-any-currentexistingones>:$NODE_MODULES:$PATH

Note to symfony / assetic users, make sure you update you assetic paths also to your new findings from above..

A new login session with linux user should prove you well on your way back to development. You should now see the correct path items on your path then when you run all these commands as your user e.g. $ npm or $ dpd , you should see no errors, and not have to append the ./ in front e.g. ./dpd -d or ./npm etc.. Dpd should run correctly, and your application, be it assetic or anything, will now have proper access to the modules.

Comments