Hello,
Running the following command:
ts-node-dev --respawn --transpileOnly --project tsconfig.server.json ./server/index.ts",
compiles files to the build folder and runs the server successfully. However, file changes are not detected in the source tree. If on the other hand I change a file in the build folder, changes are detected.
Using ts-node version 8.6.2, typescript version 3.7.5, Node v10.17.0, Yarn v1.19.1
Sample output:
yarn dev
yarn run v1.19.1
$ ts-node-dev --respawn --debug --transpileOnly --project tsconfig.server.json ./server/index.ts
Using ts-node version 8.6.2, typescript version 3.7.5
[DEBUG] 00:34:58 Starting child process -r /var/folders/7c/lb9fsb0n1z9gdzfcdv07sp4h0000gn/T/ts-node-dev-hook-626995443417242.js /projects/test-service/node_modules/ts-node-dev/lib/wrap.js ./server/index.ts
[DEBUG] 00:34:58 /projects/test-service/server/index.ts compiled in 128 ms
[DEBUG] 00:34:58 /projects/test-service/build/plugins/tenant.js compiled in 25 ms
[DEBUG] 00:34:58 /projects/test-service/build/services/OrganizationService.js compiled in 24 ms
[DEBUG] 00:34:58 /projects/test-service/build/models/Organization.js compiled in 23 ms
[DEBUG] 00:34:58 /projects/test-service/build/models/BaseModel.js compiled in 39 ms
[DEBUG] 00:34:59 /projects/test-service/build/models/EnhancedQueryBuilder.js compiled in 22 ms
[DEBUG] 00:34:59 /projects/test-service/build/services/PersistentService.js compiled in 45 ms
[DEBUG] 00:34:59 /projects/test-service/build/lib/errors/index.js compiled in 20 ms
[DEBUG] 00:34:59 /projects/test-service/build/lib/errors/errors.js compiled in 45 ms
[DEBUG] 00:34:59 /projects/test-service/build/plugins/access-token.js compiled in 15 ms
[DEBUG] 00:34:59 /projects/test-service/build/lib/auth.js compiled in 30 ms
...
Server listening on 5000...
And here is the output when detecting a change in the output folder build/ which it shouldn't be watching:
[INFO] 00:53:42 Restarting: /projects/test-service/build/lib/database.js has been modified
[DEBUG] 00:53:42 /projects/test-service/build/lib/database.js compiled in 18 ms
[DEBUG] 00:53:42 Removing all watchers from files
tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"jsx": "preserve",
"allowJs": true,
"alwaysStrict": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"removeComments": false,
"preserveConstEnums": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"sourceMap": true,
"skipLibCheck": true,
"esModuleInterop": true,
"baseUrl": "./",
"rootDir": "./server",
"paths": {
"@models/*": [
"server/models/*"
],
"@controllers/*": [
"server/controllers/*"
],
"@services/*": [
"server/services/*"
],
"@lib/*": [
"server/lib/*"
],
"@plugins/*": [
"server/plugins/*"
]
},
"experimentalDecorators": true,
"typeRoots": [
"./node_modules/@types",
"server/types"
],
"lib": ["es2018"],
"target": "es2018"
},
"exclude": [
"build",
"node_modules"
]
}
tsconfig.server.json:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "build/"
},
"include": [
"server/**/*.ts"
],
"exclude": [
"server/**/*.test.ts"
]
}
I am experiencing the same behaviour. My ts files are located at src folder and my built files are stored at dist folder. Strange thing is that if I am editing ts files in src folder that ts-node-dev detects changes, but if the file is located src/***/*.ts then it is not detected, then only the dist folder changes are being detected. What could be a source of this issue?
@whitecolor maybe you have any ideas?
EDIT: I think I have found the cause of the problem. I was using module-alias/register and this was interfering with ts-node-dev
@simoami is there something similar used in your project?
Just so you know, a workaround is to make sure module-alias/register is never loaded when running in the ts-node-dev context. Luckily, it's a simple check against an environment variable:
if (!process.env.TS_NODE_DEV) {
require('module-alias/register'); // for path resolution
}
Most helpful comment
I am experiencing the same behaviour. My ts files are located at
srcfolder and my built files are stored atdistfolder. Strange thing is that if I am editing ts files insrcfolder that ts-node-dev detects changes, but if the file is locatedsrc/***/*.tsthen it is not detected, then only thedistfolder changes are being detected. What could be a source of this issue?@whitecolor maybe you have any ideas?
EDIT: I think I have found the cause of the problem. I was using
module-alias/registerand this was interfering with ts-node-dev@simoami is there something similar used in your project?