Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用typescript时nodemon未刷新_Node.js_Typescript_Nodemon - Fatal编程技术网

Node.js 使用typescript时nodemon未刷新

Node.js 使用typescript时nodemon未刷新,node.js,typescript,nodemon,Node.js,Typescript,Nodemon,我正在开发一个包含NodeJs、express、typescript和nodemon的应用程序 但是当我更改ts文件中的一些代码时,页面没有刷新 如何在js中编译ts文件并使用nodemon(或其他工具)刷新浏览器 package.json { "name": "myapp", "version": "1.0.0", "description": "", "main": "index.js", "dependencies": { "bcryptjs": "^2.4.3

我正在开发一个包含NodeJs、express、typescript和nodemon的应用程序

但是当我更改ts文件中的一些代码时,页面没有刷新

如何在js中编译ts文件并使用nodemon(或其他工具)刷新浏览器

package.json

{
  "name": "myapp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.17.2",
    "debug": "^2.6.8",
    "dotenv": "^2.0.0",
    "express": "^4.15.3",
    "iconv-lite": "^0.4.17",
    "inversify": "^4.11.1",
    "jsonwebtoken": "^7.4.1",
    "mongoose": "^5.0.10",
    "morgan": "^1.8.2",
    "passport": "^0.3.2",
    "passport-jwt": "^2.2.1",
    "rxjs": "^5.4.2",
    "typescript": "^2.7.2",
    "winston": "^2.3.1"
  },
  "devDependencies": {
    "@types/chai": "^4.0.0",
    "@types/debug": "0.0.29",
    "@types/dotenv": "^2.0.20",
    "@types/express": "^4.0.35",
    "@types/mocha": "^2.2.41",
    "@types/mongoose": "^4.7.15",
    "@types/morgan": "^1.7.32",
    "@types/node": "^6.0.77",
    "@types/passport": "^0.3.3",
    "@types/passport-jwt": "^2.0.20",
    "chai": "^4.0.2",
    "chai-http": "^3.0.0",
    "gulp": "^3.9.1",
    "gulp-clean": "^0.3.2",
    "gulp-typescript": "^3.1.7",
    "gulp-yaml": "^1.0.1",
    "mocha": "^3.4.2",
    "mocha-typescript": "^1.1.4"
  },
  "scripts": {
    "start": "gulp build && nodemon dist/index.js",
    "build": "gulp build",
    "test": "gulp build && mocha -t 30000 dist/**/*.test.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/devslaw/TypeScript-Node.js-REST-example.git"
  },
  "keywords": [],
  "author": "Arthur Arakelyan <arthur@devslaw.com>",
  "license": "ISC",
  "homepage": "https://github.com/devslaw/TypeScript-Node.js-REST-example#readme"
}
{
“名称”:“myapp”,
“版本”:“1.0.0”,
“说明”:“,
“main”:“index.js”,
“依赖项”:{
“bcryptjs”:“^2.4.3”,
“正文分析器”:“^1.17.2”,
“调试”:“^2.6.8”,
“dotenv”:“^2.0.0”,
“快车”:“^4.15.3”,
“iconv lite”:“^0.4.17”,
“反向化”:“^4.11.1”,
“jsonwebtoken”:“^7.4.1”,
“猫鼬”:“^5.0.10”,
“摩根”:“^1.8.2”,
“passport”:“^0.3.2”,
“护照jwt”:“^2.2.1”,
“rxjs”:“^5.4.2”,
“类型脚本”:“^2.7.2”,
“温斯顿”:“^2.3.1”
},
“依赖性”:{
“@types/chai”:“^4.0.0”,
“@types/debug”:“0.0.29”,
“@types/dotenv”:“^2.0.20”,
“@types/express”:“^4.0.35”,
“@types/mocha”:“^2.2.41”,
“@types/mongoose”:“^4.7.15”,
“@types/morgan”:“^1.7.32”,
“@types/node”:“^6.0.77”,
“@types/passport”:“^0.3.3”,
“@types/passport jwt”:“^2.0.20”,
“chai”:“^4.0.2”,
“chai http”:“^3.0.0”,
“吞咽”:“^3.9.1”,
“大口喝干净”:“^0.3.2”,
“gulp typescript”:“^3.1.7”,
“吞咽yaml”:“^1.0.1”,
“摩卡咖啡”:“^3.4.2”,
“摩卡字体脚本”:“^1.1.4”
},
“脚本”:{
“开始”:“gulp build&&nodemon dist/index.js”,
“建造”:“吞咽建造”,
“测试”:“大口构建和摩卡-t 30000 dist/***.test.js”
},
“存储库”:{
“类型”:“git”,
“url”:“git”+https://github.com/devslaw/TypeScript-Node.js-REST-example.git"
},
“关键词”:[],
“作者”:“Arthur Arakelyan”,
“许可证”:“ISC”,
“主页”:https://github.com/devslaw/TypeScript-Node.js-REST-example#readme"
}

所以要知道,每当我进行更改时,我都需要停止服务器并再次运行npm start

问题在于您的启动脚本正在观看
dist/index.js
。此文件夹仅在代码重新编译为纯JavaScript时更改。因此,您需要查看TypeScript文件。最棒的是,您可以更改nodemon的默认行为。您还需要将
ts节点
添加到
package.json中

尝试将脚本设置为类似以下内容:

nodemon--watch'src/***.ts'--exec'ts node'src/index.ts

然后,您将需要设置一个包含以下内容的
nodemon.json
文件:

{
  "watch": ["src"],
  "ext": "ts",
  "exec": "ts-node ./src/index.ts"
}

另一种方法是使用ts节点的可能副本