nodemon''mocha'未被识别为内部或外部命令,可操作程序或批处理文件

时间:2021-02-10 23:13:33

Running a test for a nodejs project on windows 10 with the line in package.json as:

使用package.json中的行为Windows 10上的nodejs项目运行测试:

"test": "nodemon --exec 'mocha -R min'"

I get:

>  nodemon --exec 'mocha -R min'  

[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `'mocha -R min'`
''mocha' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...
rs
[nodemon] starting `'mocha -R min'`
''mocha' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...

7 个解决方案

#1


22  

That worked fine with the line:

这行很好用:

"test": "nodemon --exec \"mocha -R min\""

in package.json

#2


1  

If you are using windows OS the do not use the single quotes

如果您使用的是Windows操作系统,请不要使用单引号

"test": "nodemon --exec 'mocha -R min'"

“test”:“nodemon --exec'mocha -R min'”

Use this

"test": "nodemon --exec mocha -R min"

“test”:“nodemon --exec mocha -R min”

Visit: www.mycodingx.com for more

访问:www.mycodingx.com了解更多信息

#3


0  

Also, check your NODE_ENV=development if you are on Windows and are using git-bash. For some reason, it defaults to production.

另外,如果你在Windows上并使用git-bash,请检查你的NODE_ENV =开发。出于某种原因,它默认为生产。

$ echo $NODE_ENV

With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in "devDependencies"

使用--production标志(或当NODE_ENV环境变量设置为生产时),npm将不会安装“devDependencies”中列出的模块

You can verify this by checking your node_modules/ folder and see if mocha was installed. If not:

您可以通过检查node_modules /文件夹来验证这一点,看看是否安装了mocha。如果不:

$ npm install --only=dev

also:

$ NODE_ENV=development
$ npm i -D mocha

would do the trick.

会做的伎俩。

#4


0  

Inside the package.json, you need to add a new script right after the "test" script. We can create a custom script and named it as "test-watch" and the value of the "test-watch"is "nodemon --exec \"npm test\""(i.e "test-watch": "nodemon --exec \"npm test\"") After this step we can use npm run test-watch command in terminal.

在package.json中,您需要在“test”脚本之后添加一个新脚本。我们可以创建一个自定义脚本并将其命名为“test-watch”,“test-watch”的值为“nodemon --exec”npm test \“”(即“test-watch”:“nodemon - exec \“npm test \”“)在这一步之后我们可以在终端中使用npm run test-watch命令。

#5


0  

An alternative approach is to add the mocha path to the environment variables then restart the bash On your editor, navigate to the bin folder of mocha and add both paths to your system environments. All script options that have been illustrated work with this approach

另一种方法是将mocha路径添加到环境变量然后重新启动bash在编辑器上,导航到mocha的bin文件夹并将两个路径添加到系统环境中。已经说明的所有脚本选项都适用于此方法

"scripts": {
    "test": "nodemon --exec \"mocha -R min\""
}

or

"scripts": {
    "test": "nodemon --exec 'mocha -R min'"
}

or

"scripts": {
    "test": "nodemon --exec mocha -R min"
 }

in the package.json file are correct dependencies definition

在package.json文件中是正确的依赖项定义

I hope this helps fix the issue.

我希望这有助于解决问题。

#6


0  

I am no Windows kernel or any .. expert. In my case the test script kept erroring out with the message npm is not recognized as an Internal or External command.

我不是Windows内核或任何..专家。在我的情况下,测试脚本保持错误,消息npm不被识别为内部或外部命令。

a) When I had it as

a)当我这样做的时候

"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec 'npm test'"

It ran a few times and stopped and the error started occurring so when I switched to

它运行了几次并停止,错误开始发生,所以当我切换到

"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec \"npm test\""

Still I kept getting the same error of npm not recognized... And no matter how many times I issued Ctrl c, the nodemon wouldn't stop.

我仍然得到npm无法识别的相同错误...而且无论我多少次发出Ctrl c,nodemon都不会停止。

I did take the steps of restarting my laptop, uninstalled and re-installed nodeJs, updated the PATH variable in Control Panel - User Accounts - Environment variables all amounting to no end in sight.

我确实采取了重新启动我的笔记本电脑,卸载并重新安装nodeJs的步骤,更新了控制面板中的PATH变量 - 用户帐户 - 环境变量都无处可见。

This leads me to believe that somewhere or somehow, either nodemon or mocha not sure, what is hanging, so even after I had modified to escape and use double quotes as in

这让我相信某个地方或某种程度上,nodemon或mocha不确定,什么是悬挂,所以即使在我修改为escape并使用双引号之后

"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec \"npm test\""

I still kept getting the same error.

我仍然得到同样的错误。

b) So then I changed the name of the key from test-watch to test-new

b)然后我将密钥的名称从test-watch更改为test-new

"test": "mocha **/*.test.js",
"test-new": "nodemon --exec \"npm test\""

and ran npm run test-new and every tests runs fine.

然后运行npm run test-new,每个测试运行正常。

Go figure...

So I think I will stick to keeping unique test script names between different projects. I have no other explanation.... Anyone can shed light on this? Please do so...

所以我想我会坚持在不同的项目之间保留独特的测试脚本名称。我没有其他解释......任何人都可以阐明这一点?请这样做...

#7


-1  

"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec \"npm test\""

For Run

npm run test-watch

#1


22  

That worked fine with the line:

这行很好用:

"test": "nodemon --exec \"mocha -R min\""

in package.json

#2


1  

If you are using windows OS the do not use the single quotes

如果您使用的是Windows操作系统,请不要使用单引号

"test": "nodemon --exec 'mocha -R min'"

“test”:“nodemon --exec'mocha -R min'”

Use this

"test": "nodemon --exec mocha -R min"

“test”:“nodemon --exec mocha -R min”

Visit: www.mycodingx.com for more

访问:www.mycodingx.com了解更多信息

#3


0  

Also, check your NODE_ENV=development if you are on Windows and are using git-bash. For some reason, it defaults to production.

另外,如果你在Windows上并使用git-bash,请检查你的NODE_ENV =开发。出于某种原因,它默认为生产。

$ echo $NODE_ENV

With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in "devDependencies"

使用--production标志(或当NODE_ENV环境变量设置为生产时),npm将不会安装“devDependencies”中列出的模块

You can verify this by checking your node_modules/ folder and see if mocha was installed. If not:

您可以通过检查node_modules /文件夹来验证这一点,看看是否安装了mocha。如果不:

$ npm install --only=dev

also:

$ NODE_ENV=development
$ npm i -D mocha

would do the trick.

会做的伎俩。

#4


0  

Inside the package.json, you need to add a new script right after the "test" script. We can create a custom script and named it as "test-watch" and the value of the "test-watch"is "nodemon --exec \"npm test\""(i.e "test-watch": "nodemon --exec \"npm test\"") After this step we can use npm run test-watch command in terminal.

在package.json中,您需要在“test”脚本之后添加一个新脚本。我们可以创建一个自定义脚本并将其命名为“test-watch”,“test-watch”的值为“nodemon --exec”npm test \“”(即“test-watch”:“nodemon - exec \“npm test \”“)在这一步之后我们可以在终端中使用npm run test-watch命令。

#5


0  

An alternative approach is to add the mocha path to the environment variables then restart the bash On your editor, navigate to the bin folder of mocha and add both paths to your system environments. All script options that have been illustrated work with this approach

另一种方法是将mocha路径添加到环境变量然后重新启动bash在编辑器上,导航到mocha的bin文件夹并将两个路径添加到系统环境中。已经说明的所有脚本选项都适用于此方法

"scripts": {
    "test": "nodemon --exec \"mocha -R min\""
}

or

"scripts": {
    "test": "nodemon --exec 'mocha -R min'"
}

or

"scripts": {
    "test": "nodemon --exec mocha -R min"
 }

in the package.json file are correct dependencies definition

在package.json文件中是正确的依赖项定义

I hope this helps fix the issue.

我希望这有助于解决问题。

#6


0  

I am no Windows kernel or any .. expert. In my case the test script kept erroring out with the message npm is not recognized as an Internal or External command.

我不是Windows内核或任何..专家。在我的情况下,测试脚本保持错误,消息npm不被识别为内部或外部命令。

a) When I had it as

a)当我这样做的时候

"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec 'npm test'"

It ran a few times and stopped and the error started occurring so when I switched to

它运行了几次并停止,错误开始发生,所以当我切换到

"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec \"npm test\""

Still I kept getting the same error of npm not recognized... And no matter how many times I issued Ctrl c, the nodemon wouldn't stop.

我仍然得到npm无法识别的相同错误...而且无论我多少次发出Ctrl c,nodemon都不会停止。

I did take the steps of restarting my laptop, uninstalled and re-installed nodeJs, updated the PATH variable in Control Panel - User Accounts - Environment variables all amounting to no end in sight.

我确实采取了重新启动我的笔记本电脑,卸载并重新安装nodeJs的步骤,更新了控制面板中的PATH变量 - 用户帐户 - 环境变量都无处可见。

This leads me to believe that somewhere or somehow, either nodemon or mocha not sure, what is hanging, so even after I had modified to escape and use double quotes as in

这让我相信某个地方或某种程度上,nodemon或mocha不确定,什么是悬挂,所以即使在我修改为escape并使用双引号之后

"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec \"npm test\""

I still kept getting the same error.

我仍然得到同样的错误。

b) So then I changed the name of the key from test-watch to test-new

b)然后我将密钥的名称从test-watch更改为test-new

"test": "mocha **/*.test.js",
"test-new": "nodemon --exec \"npm test\""

and ran npm run test-new and every tests runs fine.

然后运行npm run test-new,每个测试运行正常。

Go figure...

So I think I will stick to keeping unique test script names between different projects. I have no other explanation.... Anyone can shed light on this? Please do so...

所以我想我会坚持在不同的项目之间保留独特的测试脚本名称。我没有其他解释......任何人都可以阐明这一点?请这样做...

#7


-1  

"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec \"npm test\""

For Run

npm run test-watch