Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

node.js - single quotes not working in 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'"
  }

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
ode-course
ode-todo-api> npm run test-watch

> [email protected] test-watch D:courses
ode-course
ode-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
ode-course
ode-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
ode-course
ode-todo-api
> mocha server/**/*.test.js



started on port 3000
  Post /todos
    √ should create a new todo (50ms)


  1 passing (1s)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Both of these should work on Windows 10 though:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...