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

泪湿孤枕 提交于 2021-02-07 09:20:21

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/47805077/why-does-running-npm-test-result-in-is-not-recognized-as-an-internal-or-ext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!