New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"sh: 1: mocha: Permission denied" - Running mocha test via "npm test" fails #1487

Closed
granmoe opened this Issue Jan 4, 2015 · 5 comments

Comments

Projects
None yet
3 participants
@granmoe
Copy link

granmoe commented Jan 4, 2015

I am attempting to use Mocha for testing in a project. I've followed the steps in this tutorial: https://www.joyent.com/blog/risingstack-writing-testable-apis-the-basics

My package.json looks like this:

{
  "name": "cyoab",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "test": "mocha test"
  },
  "dependencies": {
    "express": "~4.2.0",
    "static-favicon": "~1.0.0",
    "morgan": "~1.0.0",
    "mongoose": "*",
    "cookie-parser": "~1.0.1",
    "body-parser": "~1.0.0",
    "debug": "~0.7.4"
  },
  "devDependencies": {
    "mocha": "~2.1.0",
    "chai": "~1.10.0",
    "sinon": "~1.12.2"
  }
}

When I run "npm test" or "sudo npm test" I get the following output:

matt@matt-Inspiron-N5040:/media/matt/Storage1/Dev/cyoab$ sudo npm test

> cyoab@0.0.1 test /media/matt/Storage1/Dev/cyoab
> mocha test

sh: 1: mocha: Permission denied
npm ERR! weird error 126
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! not ok code 0

I have tried making mocha executable via chmod, but that didn't work.

I am using node v0.10.25 on Ubuntu 14.04 LTS.

Any ideas? Or am I posting this in the wrong place? I have a feeling it isn't necessarily a Mocha issue, but I'm not sure.

Thank you,

Matt

@granmoe

This comment has been minimized.

Copy link

granmoe commented Jan 4, 2015

Here is the verbose output:

matt@matt-Inspiron-N5040:/media/matt/Storage1/Dev/cyoab$ sudo npm --loglevel verbose test
npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/nodejs',
npm verb cli   '/usr/bin/npm',
npm verb cli   '--loglevel',
npm verb cli   'verbose',
npm verb cli   'test' ]
npm info using npm@1.3.10
npm info using node@v0.10.25
npm verb run-script [ 'pretest', 'test', 'posttest' ]
npm info pretest cyoab@0.0.1
npm info test cyoab@0.0.1
npm verb unsafe-perm in lifecycle true

> cyoab@0.0.1 test /media/matt/Storage1/Dev/cyoab
> mocha test

sh: 1: mocha: Permission denied
npm info cyoab@0.0.1 Failed to exec test script
npm ERR! weird error 126
npm verb exit [ 1, true ]
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! not ok code 0
@maboiteaspam

This comment has been minimized.

Copy link

maboiteaspam commented Jan 4, 2015

hi,

using ubuntu i never had to use sudo to setup mocha.
My steps are similar to

npm i -g mocha
mocha tests/*

First one create a new bin file in ~/bin/, it is executable, and ready to go.

This said, i also manually installed node, download archive, extract on desktop, link node-xxx/node/bin/{node,npm} to ~/bin, and it works fine.

Getting your problems, i d be cleaning up my system of node, then doing a cleaner setup manually.

My 2 cents!

@jbnicolai

This comment has been minimized.

Copy link
Contributor

jbnicolai commented Jan 4, 2015

Definitely not an issue related to mocha. Did you perhaps install any project-local dependencies through sudo? Give running sudo chown -R $(whoami) . from your project dir a try, and remember for the future never to install local npm dependencies as root.

@jbnicolai jbnicolai closed this Jan 4, 2015

@granmoe

This comment has been minimized.

Copy link

granmoe commented Jan 4, 2015

@jbnicolai OK, I ran sudo chown -R $(whoami) . No luck. Then I ran sudo npm cache clean then sudo rm -rf node_modules then npm install. Still having the error.

@granmoe

This comment has been minimized.

Copy link

granmoe commented Jan 4, 2015

@maboiteaspam I tried your steps and that fixed my problem. Thanks, guys. Sorry I raised this issue in the wrong place!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment