Search code examples
windowsbashnpmmocha.jsmingw-w64

Why does running npm test result in: '.' is not recognized as an internal or external command, operable program or batch file.?


I have the following installed:

  • Windows 10
  • Git bash (mingw64)
  • Node.js v8.7.0
  • npm version 5.4.2

Packages:

  • chai 4.4.1
  • mocha 3.5.0

I have a sample mocha test that will always pass when it actually runs.

The command I'm running in my shell:

npm test

Output:

./node_modules/mocha/bin/_mocha

'.' is not recognized as an internal or external command, operable program or batch file. npm ERR! Test failed. See above for more details.

For some reason I'm able to run this command directly:

./node_modules/mocha/bin/_mocha

Which results in

Sample Test

√ passes!

1 passing (4ms)

I'm guessing this has something to do with the weirdness of using a bash-like shell inside of windows, however I'm not sure how I can troubleshoot this from here.

Why might this error be happening, and is there a way to get 'npm test' to work properly without having to ditch using this windows programming environment?

Thanks & Regards


Solution

  • This may not be a perfect answer, but it fixes the issue in a way that is sufficient to continue developing:

    in my package.json file I had:

    "test" : "./node_modules/mocha/bin/_mocha"
    

    Changing this to:

    "test" : "node ./node_modules/mocha/bin/_mocha"
    

    Made it so I could run npm test command fine.

    I'm still unsure as to why the original value would not work since running that as a command in the shell works just fine.

    If anyone sees this and wants to offer some insight that would be greatly appreciated.