ts-node-dev: Cryptic errors when running ts-node-dev

Hi @whitecolor!

I was trying to use ts-node-dev develop ts actions in my project, which are just runnable typescript files.

Here’s what sometimes happens when I run yarn ts-node-dev --respawn --compile-timeout 30000 --notify=false src/actions/hello.ts:

yarn run v1.3.2
$ /path/to/project/node_modules/.bin/ts-node-dev --respawn --compile-timeout 30000 --notify=false src/actions/hello.ts
Error: Could not require /path/to/project/src/actions/hello.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_actions_hello_ts_4b7034ed73736302bd98ace10b2ead962243eb48412af14fccc6e4c9447a0ee8.js
    at compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:27:13)
    at Module.m._compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:41:36)
    at Module._extensions..js (module.js:671:10)
    at require.extensions.(anonymous function) (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:43:14)
    at Object.nodeDevHook [as .ts] (/path/to/project/node_modules/ts-node-dev/lib/hook.js:61:7)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
[ERROR] 14:11:29 Error: Could not require /path/to/project/src/actions/hello.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_actions_hello_ts_4b7034ed73736302bd98ace10b2ead962243eb48412af14fccc6e4c9447a0ee8.js
[INFO] 14:11:42 Restarting: /path/to/project/src/actions/hello.ts has been modified
Error: Could not require /path/to/project/src/lib/custom-sort-keys.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_lib_custom_sort_keys_ts_85f47a355a422b5df586503ceb1aa07cc0328a953a0c9ebe77023bef5edbbdea.js
    at compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:27:13)
    at Module.m._compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:41:36)
    at Module._extensions..js (module.js:671:10)
    at require.extensions.(anonymous function) (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:43:14)
    at Object.nodeDevHook [as .ts] (/path/to/project/node_modules/ts-node-dev/lib/hook.js:61:7)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
[ERROR] 14:12:12 Error: Could not require /path/to/project/src/lib/custom-sort-keys.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_lib_custom_sort_keys_ts_85f47a355a422b5df586503ceb1aa07cc0328a953a0c9ebe77023bef5edbbdea.js
[INFO] 14:12:16 Restarting: /path/to/project/src/actions/hello.ts has been modified
[INFO] 14:12:46 Restarting: /path/to/project/src/actions/hello.ts has been modified
Error: Could not require /path/to/project/src/lib/extract-legacy-assets-tree.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_lib_extract_legacy_assets_tree_ts_1e7f51aadf447bb3e20188e0469ac27af6675f4ba2b32e9438614f59b57bc1c5.js
    at compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:27:13)
    at Module.m._compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:41:36)
    at Module._extensions..js (module.js:671:10)
    at require.extensions.(anonymous function) (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358259402.js:43:14)
    at Object.nodeDevHook [as .ts] (/path/to/project/node_modules/ts-node-dev/lib/hook.js:61:7)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
Error [ERR_IPC_DISCONNECTED]: IPC channel is already disconnected
    at ChildProcess.target.disconnect (internal/child_process.js:746:26)
    at Pipe.channel.onread (internal/child_process.js:508:14)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I don’t understand where these are coming from and what is also strange is that I cannot make these errors reproducible for any specific content of my typescript files. For example, the error may show up at first, but then after I comment and uncomment a few lines, it disappears. At the same time, there is a likelihood that the process may completely crash, like in the example above.

Similar errors are shown when I run ts-node-dev without any options:

yarn ts-node-dev src/actions/hello.ts
yarn run v1.3.2
$ /path/to/project/node_modules/.bin/ts-node-dev src/actions/hello.ts
Error: Could not require /path/to/project/src/actions/hello.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_actions_hello_ts_7ac73806ede5e6231c25cb24297c4973531ff760794d55c116c7d946dc8640a4.js
    at compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358523172.js:27:13)
    at Module.m._compile (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358523172.js:41:36)
    at Module._extensions..js (module.js:671:10)
    at require.extensions.(anonymous function) (/private/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/ts-node-dev-hook-1518358523172.js:43:14)
    at Object.nodeDevHook [as .ts] (/path/to/project/node_modules/ts-node-dev/lib/hook.js:61:7)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
[ERROR] 14:15:33 Error: Could not require /path/to/project/src/actions/hello.ts, compiled path:/var/folders/vp/cg66j_sj5_ncxlgvgt7pjn2h0000gn/T/.ts-node/compiled/src_actions_hello_ts_7ac73806ede5e6231c25cb24297c4973531ff760794d55c116c7d946dc8640a4.js

Despite all the errors above, running yarn ts-node src/actions/hello.ts works:

yarn run v1.3.2
$ /path/to/project/node_modules/.bin/ts-node src/actions/hello.ts
ACTION OUTPUT
✨  Done in 0.97s.

What could be causing this? How can I help with debugging given that I’m unable to craft a MWE?

My env:

node 9.5.0
yarn: 1.3.2
ts-node: 4.1.0
ts-node-dev 1.0.0-pre.9
macOS High Sierra

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 48 (27 by maintainers)

Commits related to this issue

Most upvoted comments

It’s working! 🎉 (And it’s a lot faster than nodemon)

Thanks for releasing the update @whitecolor! I switched to 1.0.0-pre.11, but unfortunately the error remained. My current workaround involves using nodemon, which is probably less efficient:

"scripts": {
    "watch": "nodemon --exec ts-node --ext ts --watch src",
    "watch:broken": "ts-node-dev --respawn --notify=false"
}

yarn watch src/actions/my-action.ts

I can also confirm that I no longer see the error in 1.0.0-pre.15! 🎉 A huge thank you @whitecolor!

ts-node-dev is indeed blazing fast compared to nodemon + ts-node ❤️

Supposedly should work.

@testerez Published fixed version. probably some time is needed to ensure that bug is not here anymore.

Yes, I see the repetitive error now on a big file, I will try to figure out how to fix it.

Same issue here. MacOS too.

Ok, I’ve implemented @aikoven proposal for watching a compiled file, and removed timeout, so you may try how it works for you.

I don’t actually think that checking file existence takes many CPU resources

Not the checking itself, but since there’s no sleep, the loop may iterate a lot of times before the file is created.

How about this: have a separate script that waits for a file via e.g. fs.watch(), then execute it with a blocking call to child_process.execFileSync()

Here’s the error message:

Error: Could not require /opt/app/src/index.ts, compiled path:/tmp/.ts-node/compiled/src_index_ts_77422fb8b702bc764b30afe40edb019b94fe582fc7d48fc5f171fbf1d04ef6b9.js
    at compile (/tmp/ts-node-dev-hook-1523337655467.js:30:13)
    at Module.m._compile (/tmp/ts-node-dev-hook-1523337655467.js:44:36)
    at Module._extensions..js (module.js:660:10)
    at require.extensions.(anonymous function) (/tmp/ts-node-dev-hook-1523337655467.js:46:14)
    at Object.nodeDevHook [as .ts] (/opt/app/node_modules/ts-node-dev/lib/hook.js:61:7)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
[ERROR] 05:21:02 Error: Could not require /opt/app/src/index.ts, compiled path:/tmp/.ts-node/compiled/src_index_ts_77422fb8b702bc764b30afe40edb019b94fe582fc7d48fc5f171fbf1d04ef6b9.js

Increasing the user watches limit did the work. It’s working normally now. Thank you

Sorry for bothering you with my errors. I saw this issue and I kinda automatically thought that it’s related.

Hm, I probably know where the issue, it just requires more tricks to workaround, stay tuned.

I published new version check it, please.

As stated it works fine for me on Windows 10 but not for another colleague on Mac OS X. So that seems to be one common factor.

Other env details:

Node 8.9
yarn 1.3.2
ts-node 4.1.0
ts-node-dev 1.0.0-pre.11
typescript 2.7.1
macOS High Sierra v10.13.3

You may try the latest published version, maybe something will change, maybe not. )