【问题标题】:single quotes not working in package.json单引号在 package.json 中不起作用
【发布时间】:2018-06-14 17:19:06
【问题描述】:

我想让我的 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

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

【问题讨论】:

    标签: node.js npm package.json nodemon


    【解决方案1】:

    不幸的是,在使用 npm 时,操作系统和 shell 可能会让人头疼。有些东西在一台计算机上运行,​​有些在另一台计算机上运行。

    这些都应该在 Windows 10 上运行:

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

    【讨论】:

    • 谢谢...真不敢相信我想不出那个大声笑,因为它是如此简单...
    • 无论使用什么系统和外壳,有没有办法让命令正常工作?
    • @cjsimon 我认为不使用单引号是让它在 *nix 和 Windows 上工作的方法。采用 ””。根据this 页面,使用三个反斜杠可能是最好的选择(出于某种原因)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多