ts-node-dev 不应用自动重新加载的更改
ts-node-dev doesn't apply changes in auto reload
我已经在 Typescript 中使用 FeathersJS 构建了一个应用程序,但是尽管 typescript 的 nodemon (ts-node-dev) 说当 typescript 文件被更改时服务器已经重新启动,但更改没有应用。
我总是需要终止应用程序并重新启动才能看到变化。
这是日志:
[INFO] 15:43:51 Restarting: C:\api\src\models\favorites.model.ts has been modified
Using ts-node version 7.0.1, typescript version 3.9.3
info: Feathers application started on http://localhost:3030
这是 package.json 上的 dev
脚本:
ts-node-dev --no-notify src/
这里是 tsconfig.json:
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"outDir": "./lib",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true
},
"exclude": [
"test"
]
}
这里是 package.json:
{
"homepage": "",
"private": true,
"main": "src",
"keywords": [
"feathers"
],
"contributors": [],
"bugs": {},
"directories": {
"lib": "src",
"test": "test/",
"config": "config/"
},
"engines": {
"node": "^12.0.0",
"npm": ">= 3.0.0"
},
"scripts": {
"test": "npm run compile && npm run mocha",
"dev": "ts-node-dev --no-notify src/",
"start": "npm run compile && node lib/",
"mocha": "ts-mocha \"test/**/*.ts\" --recursive --exit",
"compile": "shx rm -rf lib/ && tsc"
},
"prettier":{
"singleQuote": true
},
"standard": {
"env": [
"mocha"
],
"ignore": []
},
"types": "lib/",
"dependencies": {
"@feathersjs/authentication": "^4.5.3",
"@feathersjs/authentication-local": "^4.5.4",
"@feathersjs/authentication-oauth": "^4.5.4",
"@feathersjs/configuration": "^4.5.3",
"@feathersjs/errors": "^4.5.3",
"@feathersjs/express": "^4.5.4",
"@feathersjs/feathers": "^4.5.3",
"@feathersjs/transport-commons": "^4.5.3",
"compression": "^1.7.4",
"cors": "^2.8.5",
"feathers-mongoose": "^8.3.0",
"helmet": "^3.22.0",
"mongodb-core": "^3.2.7",
"mongoose": "^5.9.16",
"serve-favicon": "^2.5.0",
"winston": "^3.2.1"
},
"devDependencies": {
"@types/compression": "^1.7.0",
"@types/cors": "^2.8.6",
"@types/helmet": "0.0.47",
"@types/jsonwebtoken": "^8.5.0",
"@types/mocha": "^7.0.2",
"@types/mongoose": "^5.7.21",
"@types/serve-favicon": "^2.5.0",
"axios": "^0.19.2",
"mocha": "^7.2.0",
"nodemon": "^2.0.4",
"shx": "^0.3.2",
"ts-mocha": "^7.0.0",
"ts-node-dev": "^1.0.0-pre.44",
"tslint": "^6.1.2",
"typescript": "^3.9.3"
}
}
您需要告诉编译器监视更改。添加以下脚本或使用监视标志调整您的 compile
脚本:
"watch-ts": "tsc -w"
或
"compile": "shx rm -rf lib/ && tsc -w"
我仔细查看了您的脚本,在我看来您应该从编译文件(我猜它们在 lib 文件夹中)启动服务器。如果这是真的,你的 运行 宁服务器的脚本应该是例如:
"dev": "ts-node-dev --no-notify lib/server.js"
并且您需要在两个单独的终端选项卡中运行:
npm run compile
和
npm run dev
ionut-t 的回答是一种可行的解决方法,但是这个问题很好,但没有回答。该解决方案实质上绕过了 ts-node-dev
的 ts-node
方面,仅将其用于重新加载,这错过了 ts-node-dev
的全部好处。恕我直言,要么是 ts-node-dev
有问题,要么是 feathersjs 如何开箱即用地配置它,我猜它很快就会以某种方式得到解决(如果还没有的话)。
更新:
我是对的...升级后 ts-node-dev
它现在可以在单个终端中完美运行。
升级:
npm i --save-dev ts-node-dev
- 损坏的版本是1.0.0-pre.44
- 我使用的固定版本是1.0.0-pre.50
将 --exit-child
添加到 npm 开发脚本似乎对我有用。
"dev": "ts-node-dev --no-notify --exit-child src/",
我已经在 Typescript 中使用 FeathersJS 构建了一个应用程序,但是尽管 typescript 的 nodemon (ts-node-dev) 说当 typescript 文件被更改时服务器已经重新启动,但更改没有应用。 我总是需要终止应用程序并重新启动才能看到变化。
这是日志:
[INFO] 15:43:51 Restarting: C:\api\src\models\favorites.model.ts has been modified
Using ts-node version 7.0.1, typescript version 3.9.3
info: Feathers application started on http://localhost:3030
这是 package.json 上的 dev
脚本:
ts-node-dev --no-notify src/
这里是 tsconfig.json:
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"outDir": "./lib",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true
},
"exclude": [
"test"
]
}
这里是 package.json:
{
"homepage": "",
"private": true,
"main": "src",
"keywords": [
"feathers"
],
"contributors": [],
"bugs": {},
"directories": {
"lib": "src",
"test": "test/",
"config": "config/"
},
"engines": {
"node": "^12.0.0",
"npm": ">= 3.0.0"
},
"scripts": {
"test": "npm run compile && npm run mocha",
"dev": "ts-node-dev --no-notify src/",
"start": "npm run compile && node lib/",
"mocha": "ts-mocha \"test/**/*.ts\" --recursive --exit",
"compile": "shx rm -rf lib/ && tsc"
},
"prettier":{
"singleQuote": true
},
"standard": {
"env": [
"mocha"
],
"ignore": []
},
"types": "lib/",
"dependencies": {
"@feathersjs/authentication": "^4.5.3",
"@feathersjs/authentication-local": "^4.5.4",
"@feathersjs/authentication-oauth": "^4.5.4",
"@feathersjs/configuration": "^4.5.3",
"@feathersjs/errors": "^4.5.3",
"@feathersjs/express": "^4.5.4",
"@feathersjs/feathers": "^4.5.3",
"@feathersjs/transport-commons": "^4.5.3",
"compression": "^1.7.4",
"cors": "^2.8.5",
"feathers-mongoose": "^8.3.0",
"helmet": "^3.22.0",
"mongodb-core": "^3.2.7",
"mongoose": "^5.9.16",
"serve-favicon": "^2.5.0",
"winston": "^3.2.1"
},
"devDependencies": {
"@types/compression": "^1.7.0",
"@types/cors": "^2.8.6",
"@types/helmet": "0.0.47",
"@types/jsonwebtoken": "^8.5.0",
"@types/mocha": "^7.0.2",
"@types/mongoose": "^5.7.21",
"@types/serve-favicon": "^2.5.0",
"axios": "^0.19.2",
"mocha": "^7.2.0",
"nodemon": "^2.0.4",
"shx": "^0.3.2",
"ts-mocha": "^7.0.0",
"ts-node-dev": "^1.0.0-pre.44",
"tslint": "^6.1.2",
"typescript": "^3.9.3"
}
}
您需要告诉编译器监视更改。添加以下脚本或使用监视标志调整您的 compile
脚本:
"watch-ts": "tsc -w"
或
"compile": "shx rm -rf lib/ && tsc -w"
我仔细查看了您的脚本,在我看来您应该从编译文件(我猜它们在 lib 文件夹中)启动服务器。如果这是真的,你的 运行 宁服务器的脚本应该是例如:
"dev": "ts-node-dev --no-notify lib/server.js"
并且您需要在两个单独的终端选项卡中运行:
npm run compile
和
npm run dev
ionut-t 的回答是一种可行的解决方法,但是这个问题很好,但没有回答。该解决方案实质上绕过了 ts-node-dev
的 ts-node
方面,仅将其用于重新加载,这错过了 ts-node-dev
的全部好处。恕我直言,要么是 ts-node-dev
有问题,要么是 feathersjs 如何开箱即用地配置它,我猜它很快就会以某种方式得到解决(如果还没有的话)。
更新:
我是对的...升级后 ts-node-dev
它现在可以在单个终端中完美运行。
升级:
npm i --save-dev ts-node-dev
- 损坏的版本是1.0.0-pre.44
- 我使用的固定版本是1.0.0-pre.50
将 --exit-child
添加到 npm 开发脚本似乎对我有用。
"dev": "ts-node-dev --no-notify --exit-child src/",