单引号在package.json中不起作用 [英] single quotes not working in package.json

查看:282
本文介绍了单引号在package.json中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的package.json能够在npm 5.5.1的Windows 10上使用npm run test-watch命令运行.在我的package.json中:

I'd like to get my package.json to be able to run using the command npm run test-watch on Windows 10 with npm 5.5.1. In my package.json:

  "scripts": {
    "test": "mocha server/**/*.test.js",
    "test-watch": "nodemon --exec 'npm test'"
  }

但是,我这样奇怪地解释了代码,在其中只有一个引号.我实际上正在学习Udemy课程,因此它似乎对讲师有效.但是,这是我得到的输出:

However, I this interpretes the code strangely to have a single quote in there. I'm actually following a Udemy course so it appears to work for the instructor. However, here is the output I get:

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...

要使它正常工作,我需要更改什么?看来是在引号上保留引号.我似乎无法绕开它.当我直接运行命令时,它会起作用:

What do I need to change to get this to work? It appears to be keeping the quotes on the string. I can't seem to get around it though. When I run the command directly, it works:

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时,操作系统和外壳程序可能会引起严重的头痛.有些事情可以在一台计算机上运行,​​而某些事情可以在另一台计算机上运行.

Unfortunately, the operating system and shell can cause a massive headache when using npm. Some things work on one computer and some on another.

尽管这两种方法都可以在Windows 10上运行:

Both of these should work on Windows 10 though:

"test-watch": "nodemon --exec \"npm test\""
"test-watch": "nodemon --exec npm test"

这篇关于单引号在package.json中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆