当前位置: 首页 > 知识库问答 >
问题:

使用typescript时nodemon未刷新

曹鸿风
2023-03-14

我正在开发一个带有NodeJs、Express、types cript和no清新的应用程序。

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

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

包裹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"
}

所以,每次我进行更改,我都需要停止服务器并重新运行npm start

共有1个答案

柳培
2023-03-14

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

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

nodemon-watch'src/***/*。ts’--exec“ts node”src/index。ts

然后,您需要设置一个节点。json文件还包含以下内容:

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

 类似资料:
  • 使用nodemon livereolad nodemon supervisor npm i -D nodemon 修改package.json "scripts": { "start": "./node_modules/.bin/nodemon bin/www" }, 然后 npm start 改一下routes/index.js里的代码试试,你再也不要重启了 演示效果

  • Nodemon 是一款非常实用的工具,用来监控你 node.js 源代码的任何变化和自动重启你的服务器。 Nodemon 是一款完美的开发工具,可以使用 npm 安装。 设计原则 更少的标志更好 适用于所有平台 更少的功能 让个人建立在nodemon之上 提供所有CLI功能作为API 贡献必须通过测试

  • saif@saifrakib:/Project/NodeJs/second node$npm安装-g nodemon npm WARN检查权限缺少对 /usr/local/libnpm WARN可选跳过可选依赖项的写访问权限:fsenents@~2.3.2(node_modules/nodemo/node_modules/chokitar/node_modules/fswients): npm W

  • 似乎刷新问题之前讨论过,但没有一个解决方案对我有效。 我正在尝试做的事情:我正在使用FragmentStatePagerAdapter。适配器的每个位置都保存一个片段,该片段具有类似国际象棋的线性布局,每个单元格由CheckedTextView表示。 问题:即使正确存储和分配了值,视图仍然不能刷新,视图中单元格的值也不会得到更新。 我尝试过的建议都不起作用:1。调用Adapter.NotifyDa