最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

单引号在package.json中不起作用

运维笔记admin10浏览0评论

单引号在package.json中不起作用

单引号在package.json中不起作用

我想让我的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课程,所以它似乎适用于教练。但是,这是我得到的输出:

PS D:\courses\node-course\node-todo-api> npm run test-watch

> [email protected] 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`

> [email protected] 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)
回答如下:

不幸的是,操作系统和shell在使用npm时会引起很大的麻烦。有些东西在一台计算机上运行,​​另一些在另一台计

这两个应该适用于Windows 10:

"test-watch": "nodemon --exec \"npm test\""
"test-watch": "nodemon --exec npm test"
发布评论

评论列表(0)

  1. 暂无评论