我想让我的 package.json 能够在带有 npm 5.5.1 的 Windows 10 上使用命令 npm run test-watch 运行。在我的 package.json 中:
"scripts": {
"test": "mocha server/**/*.test.js",
"test-watch": "nodemon --exec 'npm test'"
}
但是,我将代码奇怪地解释为其中有一个单引号。我实际上正在学习 Udemy 类(class),所以它似乎对讲师有用。但是,这是我得到的输出:
PS D:\courses\node-course\node-todo-api> npm run test-watch
> todo-api@1.0.0 test-watch D:\courses\node-course\node-todo-api
> nodemon --exec 'npm test'
[nodemon] 1.14.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `'npm test'`
''npm' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...
我需要更改什么才能使其正常工作?它似乎将引号保留在字符串上。我似乎无法绕过它。当我直接运行命令时,它起作用了:
PS D:\courses\node-course\node-todo-api> nodemon --exec 'npm test'
[nodemon] 1.12.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `npm test`
> todo-api@1.0.0 test D:\courses\node-course\node-todo-api
> mocha server/**/*.test.js
started on port 3000
Post /todos
√ should create a new todo (50ms)
1 passing (1s)
最佳答案
不幸的是,在使用 npm 时,操作系统和 shell 可能会让人头疼。有些东西在一台计算机上工作,有些在另一台计算机上工作。
虽然这两个都应该在 Windows 10 上工作:
"test-watch": "nodemon --exec \"npm test\""
"test-watch": "nodemon --exec npm test"
关于node.js - 单引号在 package.json 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48104380/