mocha.el icon indicating copy to clipboard operation
mocha.el copied to clipboard

Cannot find node on Windows

Open bleggett opened this issue 9 years ago • 10 comments

This is likely a pathing issue, but running mocha results in

-*- mode: mocha-compilation; default-directory: "c:/Source/MyProject/" -*-
Mocha started at Tue Sep 27 15:13:46

 node node_modules/.bin/mocha --recursive --reporter dot c:/Source/MyProject/tests/client/api/auth.unit.js
module.js:327
    throw err;
    ^

Error: Cannot find module 'c:\Source\MyProject\node'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:974:3

Mocha exited abnormally with code 1 at Tue Sep 27 15:13:46

node.exe is in my windows $PATH.

I then tried setting mocha-which-node, with and without an escaped path, and I get the same error.

  '(mocha-which-node "C:\\Program\\ Files\\nodejs\\node.exe")

bleggett avatar Sep 27 '16 19:09 bleggett

Where did you set mocha-which-node? Setting it should change the output in the compilation buffer to the path you set it to, did you see that change?

I'm not sure how emacs looks up things on the windows path (I have never used emacs on windows).

scottaj avatar Sep 27 '16 19:09 scottaj

@scottaj In my .emacs, so yeah would expect it to work, I'm not sure either.

bleggett avatar Sep 27 '16 20:09 bleggett

Can you post the output of the test run buffer after setting that value, so I can see the command it is generating? Are you sure you are setting the variable after the plugin loads so that it is not overriden by the plugin's default?

You may want to try setting the value in the customize UI and see if it sticks then.

scottaj avatar Sep 28 '16 00:09 scottaj

Any update on this? I'll close it otherwise.

scottaj avatar Dec 12 '16 17:12 scottaj

Same problem here.

I have changed the path of mocha-which-node and I can see the new path in the test buffer, but still not working:

 "c:\Program Files\nodejs\node" node_modules/.bin/mocha --recursive --reporter dot --opts e:/Desarrollo/IGT.POS.WebAdmin/src/WebAdmin/mocha.opts e:/Desarrollo/IGT.POS.WebAdmin/src/WebAdmin/src/app/ui/Login.spec.tsx
module.js:327
    throw err;
    ^

Error: Cannot find module 'c:\Program Files\nodejs\node'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3

Any idea?

jmhdez avatar Jan 12 '17 16:01 jmhdez

If you copy that command to your CLI, does it work or give the same error? The error you posted is a nodeJS error, not an error from this plugin. This indicates node actually did run. What is weird is that it looks like it tried to run its own executable, and then blew up doing that.

scottaj avatar Jan 12 '17 16:01 scottaj

I've made it work using the following settings:

((nil . (
            (mocha-which-node . "")
            (mocha-command . ".\node_modules\.bin\mocha.cmd")
            (mocha-environment-variables . "NODE_ENV=test")
            (mocha-options . "--recursive --reporter dot -t 5000")
            (mocha-project-test-directory . "test")
            (mocha-reporter . "spec")
            )))

It looks like in windows it's easier to just run the mocha.cmd command installed with mocha than trying to run the script through node.

Thanks for your help and for this great package :-)

jmhdez avatar Jan 12 '17 19:01 jmhdez

@jmhdez any idea how that would translate to 'customize', hoping to avoid having to make a file for every project but have yet to get this package to work unfortunetly

vidjuheffex avatar Jul 20 '17 15:07 vidjuheffex

@vidjuheffex the simplest way I found to make it work was to set this vars in .emacs.d to run the mocha installed locally in each project using the mocha.opts for that project.

(setq mocha-command ".\\node_modules\\.bin\\mocha.cmd")
(setq mocha-which-node "")

jmhdez avatar Jul 20 '17 16:07 jmhdez

Works for me! Strangely the exact same values in customize do not work. I also am not sure what you mean by mocha.opts, but I do know that mocha-text-project is working

vidjuheffex avatar Jul 20 '17 16:07 vidjuheffex