ts-node-dev: Package is broken with node 14 : fs.watch with recursive is throwing on incompatible os

Hello,

I just upgraded node to v14 on my fedora 31. It seems this package is now broken due to this commit : https://github.com/nodejs/node/commit/67e067eb06

Also check updated doc : fs.watch doc

The recursive option is only supported on macOS and Windows. An ERR_FEATURE_UNAVAILABLE_ON_PLATFORM exception will be thrown when the option is used on a platform that does not support it.

Output error example :

# npx ts-node-dev src/main.ts
Using ts-node version 8.4.1, typescript version 3.8.3
TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
    at Object.watch (fs.js:1441:11)
    at add (/root/backend/node_modules/filewatcher/index.js:74:34)
    at /root/backend/node_modules/filewatcher/index.js:93:5
    at FSReqCallback.oncomplete (fs.js:176:5)

Using recursive: true now throws an Error that is not handled. https://github.com/whitecolor/ts-node-dev/blob/c0df64c43455d2f8ef144eb9defcd05b6fc52486/lib/index.js#L45

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 54
  • Comments: 21 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Will check everything and release it with chokidar soon.

Run using ts-node-dev --poll src/index.ts

Hey, while waiting for a fix in filewatcher or here, I just made a quick & dirty fix by disabling the recursive option on Linux and Node 14, to be able to use ts-node-dev right now in this environment.

To select this specific commit:

npm add -D 'mmvsk/ts-node-dev#d7e9cfbad414bcc5fc9ddb5cf75a74496a9e4549'

Replaced with chokidar in the latest published.

Bump - just updated to node v14 and got the same issue. Downgrading to v13 or lower works just fine. (I recommend using https://github.com/tj/n or https://github.com/nvm-sh/nvm)

Edit: It seems like ts-node had a similar issue a while ago? https://github.com/nodejs/node/issues/20258

@mmvsk doesn’t your PR simply disable recursive watching on linux / node 14? or would it work on linux machines with recursive watching as well (and I am mis-understanding something)?

P.S. perhaps using something like this (or another alternative fs.watch wrapper, I don’t know which of these packages actually solves this issue and is performant/reliable enough) would alleviate the issue?

Yes, it’s precisely what it does. But actually the recursive option never worked on Linux: before Node 14 fs-watch was silently failing, and now it raise an error. So this PR is basically reverting ts-node-dev to its original behavior.

Actually it “works” on Linux in the same way it was working before Node 14: by using the dependency chain built by the imports. So it’s possible to have some missed detections if a file is modified in a deep directory without being imported anywhere - in the exact same way as in Node 13 and before - but in most cases it will work just fine.

And I agree with you: ideally, fs-watch should be replaced and node-watch seems like a good candidate for that, better than chokidar that was proposed earlier in this thread.

tl;dr

  • PR #149 fix this actual issue, by restoring the same behavior as before Node 14
  • As an improvement, fs-watch should be replaced by a better alternative (such as node-watch)

@ssomlk you should node:13-alpine if you want to use Node 13 instead of latest.

Here you can find a list of all the released tags: https://hub.docker.com/_/node/ I think that Docker has a Get Started guide that may help you with these basic concepts.

Problem is in underlying filewatcher issue is already raised in there and PR made

Thnx for @onlurking for making fix for it

But it seems like filewatcher has not been updated for a while tho, so not sure if it will get merged in there 😞

@whitecolor I think we can fix this issue by migrating to chokidar instead of fs.watch. Does it make sense?