I am using ts-node-dev in my project (+3K source files).
As a local development machine I am using macOS Catalina and everything is fine.
Once I run project in Docker container (Debian GNU/Linux 9 (stretch)) I am getting weird errors for random files.
Error is always same (The argument 'path' must be a string or Uint8Array without null bytes.):
[DEBUG] 22:16:25 /home/wwwroot/myproject/packages/gql/src/modules/news-feed-extended/news-feed-extended.service.ts compiled in 16 ms
Compilation error in /home/wwwroot/myproject/packages/gql/src/modules/name-data/name-data.service.ts
TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string or Uint8Array without null bytes. Received '/home/wwwroot/myproject/packages/gql/.cache/compiled/src_modules_name_data_name_data_service_ts_c3f5059df45d91d7833d37093922a081...
at Object.openSync (fs.js:454:10)
at Object.writeFileSync (fs.js:1362:35)
at writeCompiled (/home/wwwroot/myproject/node_modules/ts-node-dev/lib/compiler.js:218:30)
at Object.compile (/home/wwwroot/myproject/node_modules/ts-node-dev/lib/compiler.js:241:17)
at /home/wwwroot/myproject/node_modules/ts-node-dev/lib/index.js:135:30
at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)
error Command failed with exit code 1.
Important is that it's always different file.
I am pretty sure, that this files are valid, I can run it outside docker.
I don't totally understand what is wrong. Any tips?
Both system are using v12.18.3
ts-node-dev version is "ts-node-dev": "^1.0.0-pre.61"
Starting command is:
yarn ts-node-dev --debug --no-notify --respawn --transpile-only --ignore-watch node_modules --cache-directory .cache --watch src src/boot.ts
Thank you in advice
try to remove watch src watching required files with --watch is not supported.
Removed and changed to: yarn ts-node-dev --debug --no-notify --respawn --transpile-only --ignore-watch node_modules --cache-directory .cache src/boot.ts
Same problem in docker run.
Outside docker is working fine (looks it is faster ??).
Something wrong with --cache-directory. Btw you don't want the cache directory to be on the docker volume (if you are mounting your code with volumes). Outside docker, it will be faster of course. Also, you may need --poll option if you watching volumes.
Looks like it help me.
Fixed by storing cache in docker os (--cache-directory /tmp/.cache)
App is running. But I am facing another problem.
Once it is ready, its reloaded without any changes (looks like old instance is not killed) and I am getting an error that address already in use (it is web server app)
Note: I moved all codes from shared docker volumes into docker system and its same problem - reloaded without any changes and crashed
It should any way print the cause of reloading, there is --debug flag, also, try --exit-child flag and --tree-kill.
I Used with your hint and it is same, with debug flag there is nothing useful.
Also I removed all my code. To test single skeleton app
See full log:
-> yarn workspace @dc/gql2 start:dev
yarn workspace v1.22.4
yarn run v1.22.4
$ yarn ts-node-dev --debug --exit-child --tree-kill --no-notify --respawn --transpile-only --ignore-watch node_modules --cache-directory /tmp/.cache src/boot.ts
$ /home/wwwroot/myproject/node_modules/.bin/ts-node-dev --debug --exit-child --tree-kill --no-notify --respawn --transpile-only --ignore-watch node_modules --cache-directory /tmp/.cache src/boot.ts
Ignore watch: [ 'node_modules' ]
[INFO] 11:03:51 ts-node-dev ver. 1.0.0-pre.65 (using ts-node ver. 8.10.2, typescript ver. 4.0.3)
[DEBUG] 11:03:51 Starting child process -r /tmp/ts-node-dev-hook-9863304373624151.js /home/wwwroot/myproject/node_modules/ts-node-dev/lib/wrap.js src/boot.ts
[DEBUG] 11:03:51 /home/wwwroot/myproject/packages/gql2/src/boot.ts added to watcher
[DEBUG] 11:03:51 /home/wwwroot/myproject/packages/gql2/src/boot.ts compiled in 91 ms
[DEBUG] 11:03:51 /home/wwwroot/myproject/packages/gql2/src/main.ts added to watcher
[DEBUG] 11:03:51 /home/wwwroot/myproject/packages/gql2/src/main.ts compiled in 60 ms
[DEBUG] 11:03:52 /home/wwwroot/myproject/packages/gql2/src/pipes/validator.ts added to watcher
[DEBUG] 11:03:52 /home/wwwroot/myproject/packages/gql2/src/pipes/validator.ts compiled in 63 ms
[DEBUG] 11:03:52 /home/wwwroot/myproject/packages/gql2/src/const/env.ts added to watcher
[DEBUG] 11:03:52 /home/wwwroot/myproject/packages/gql2/src/const/env.ts compiled in 22 ms
[DEBUG] 11:03:52 /home/wwwroot/myproject/packages/gql2/src/utils/env.ts added to watcher
[DEBUG] 11:03:52 /home/wwwroot/myproject/packages/gql2/src/utils/env.ts compiled in 13 ms
[DEBUG] 11:03:52 /home/wwwroot/myproject/packages/gql2/src/app/app.module.ts added to watcher
[DEBUG] 11:03:52 /home/wwwroot/myproject/packages/gql2/src/app/app.module.ts compiled in 68 ms
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/const/connections.ts added to watcher
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/const/connections.ts compiled in 6 ms
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/core/middleware/playground.middleware.ts added to watcher
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/core/middleware/playground.middleware.ts compiled in 30 ms
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/utils/request.ts added to watcher
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/utils/request.ts compiled in 17 ms
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/system/entity.ts added to watcher
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/system/entity.ts compiled in 5 ms
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/system/entity-archive.ts added to watcher
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/system/entity-archive.ts compiled in 5 ms
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/system/entity-kvido.ts added to watcher
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/system/entity-kvido.ts compiled in 3 ms
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/app/graphql.module.ts added to watcher
[DEBUG] 11:03:53 /home/wwwroot/myproject/packages/gql2/src/app/graphql.module.ts compiled in 34 ms
[DEBUG] 11:03:54 /home/wwwroot/myproject/packages/gql2/src/system/module.ts added to watcher
[DEBUG] 11:03:54 /home/wwwroot/myproject/packages/gql2/src/system/module.ts compiled in 4 ms
[DEBUG] 11:03:54 /home/wwwroot/myproject/packages/gql2/src/system/resolver.ts added to watcher
[DEBUG] 11:03:54 /home/wwwroot/myproject/packages/gql2/src/system/resolver.ts compiled in 4 ms
[DEBUG] 11:03:54 /home/wwwroot/myproject/packages/gql2/src/controllers/jonas/jonas.module.ts added to watcher
[DEBUG] 11:03:54 /home/wwwroot/myproject/packages/gql2/src/controllers/jonas/jonas.module.ts compiled in 11 ms
[DEBUG] 11:03:54 /home/wwwroot/myproject/packages/gql2/src/controllers/jonas/jonas.controller.ts added to watcher
[DEBUG] 11:03:55 /home/wwwroot/myproject/packages/gql2/src/controllers/jonas/jonas.controller.ts compiled in 23 ms
[DEBUG] 11:03:55 /home/wwwroot/myproject/packages/gql2/src/controllers/jonas/jonas.module.ts compiled in 14 ms
[DEBUG] 11:03:55 /home/wwwroot/myproject/packages/gql2/src/controllers/jonas/jonas.service.ts added to watcher
[DEBUG] 11:03:55 /home/wwwroot/myproject/packages/gql2/src/controllers/jonas/jonas.service.ts compiled in 112 ms
[DEBUG] 11:03:55 /home/wwwroot/myproject/packages/gql2/src/const/database.ts added to watcher
[DEBUG] 11:03:55 /home/wwwroot/myproject/packages/gql2/src/const/database.ts compiled in 7 ms
[DEBUG] 11:03:55 /home/wwwroot/myproject/packages/gql2/src/app/system.controller.ts added to watcher
[DEBUG] 11:03:55 /home/wwwroot/myproject/packages/gql2/src/app/system.controller.ts compiled in 26 ms
[DEBUG] 11:03:55 structured-stack added to watcher
[Nest] 1930 - 10/15/2020, 11:03:55 AM [Core] Ready in port 4450
[Nest] 1930 - 10/15/2020, 11:03:55 AM [Core] App is ready 665 +1ms
[Nest] 1930 - 10/15/2020, 11:03:55 AM [Core] Ready in port 4450 +4ms
[Nest] 1930 - 10/15/2020, 11:03:55 AM [Core] App is ready 256 +1ms
Error: listen EADDRINUSE: address already in use 0.0.0.0:4450
at Server.setupListenHandle [as _listen2] (net.js:1313:16)
at listenInCluster (net.js:1361:12)
at doListen (net.js:1498:7)
at processTicksAndRejections (internal/process/task_queues.js:85:21)
[DEBUG] 11:03:55 Child error
[ERROR] 11:03:55 Error: listen EADDRINUSE: address already in use 0.0.0.0:4450
[DEBUG] 11:03:55 Disconnecting from child
[DEBUG] 11:03:55 Sending SIGTERM kill to child pid 1930
[DEBUG] 11:03:55 Using tree-kill
Child got SIGTERM, exiting.
[DEBUG] 11:03:55 Child exited with code 0
You can see that app is starting twice (in same time):
[Nest] 1930 - 10/15/2020, 11:03:55 AM [Core] Ready in port 4450 // ONE RUN
[Nest] 1930 - 10/15/2020, 11:03:55 AM [Core] App is ready 665 +1ms // ONE RUN
[Nest] 1930 - 10/15/2020, 11:03:55 AM [Core] Ready in port 4450 +4ms // SECOND RUN
[Nest] 1930 - 10/15/2020, 11:03:55 AM [Core] App is ready 256 +1ms // SECOND RUN
Question is, why is starting twice.
Ok, finally I found a problem with duplicate start. Its problem in my code, sorry.
So, to fix my first issue:
Use cache folder inside docker using --cache-directory /tmp/.cache
Thank you for your help!
You actually may not worry about setting --cache-folder in the container, it uses system tmp.
--no-notify is too by default.