首页 > 解决方案 > nodemon 在 Windows 上通过 npm 脚本启动时不观看

问题描述

我尝试在 Windows 上通过 npm 脚本运行 nodemon。起初我在命令提示符下运行脚本字符串。 ./node_modules/.bin/nodemon -e ts --watch 'src/' --exec "npm run compile-component && node dist/index.js" 它可以正常工作。我更改文件夹中的文件,nodemon 监视它并重新启动服务器。但是当我尝试用 npm 运行它时,nodemon 启动了。当我在下面启动脚本时,您可以看到日志。

PS D:\Projects\my-project> npm run dev

> my-project@1.0.0 dev D:\Projects\my-project
> nodemon -e ts --watch 'src/' --exec "npm run compile-component && node dist/index.js"

[nodemon] 2.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): 'src\'
[nodemon] watching extensions: ts
[nodemon] starting `npm run compile-component && node dist/index.js`

> my-project@1.0.0 compile-component D:\Projects\my-project
> tsc -p tsconfig.json

App is listening on port 3000

但是当我更改文件时,nodemon 不会对它做出反应。我不明白为什么会这样。我该如何解决这个问题? package.json文件如下所示。

{
  "name": "my-project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    ...
  },
  "devDependencies": {
    ...
  },
  "scripts": {
    "compile-component": "tsc -p tsconfig.json",
    "dev": "./node_modules/.bin/nodemon -e ts --watch 'src/' --exec \"npm run compile-component && node dist/index.js\""
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

标签: node.jsnpmnodemon

解决方案


推荐阅读