webcontainer-core icon indicating copy to clipboard operation
webcontainer-core copied to clipboard

fs.watch recursive option problem

Open dorakadri opened this issue 1 year ago • 1 comments

when trying to use this feature : webcontainerInstance.fs.watch('/src', { recursive: true }, (event, filename) => { console.log(file: ${filename} action: ${event}); }); [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js

dorakadri avatar Feb 16 '24 20:02 dorakadri

I encountered this as well. It means that ava --watch doesn't work.

rotu avatar Apr 28 '24 19:04 rotu

Same error here

vadolasi avatar Aug 25 '24 04:08 vadolasi

I am also seeing this error.

This does not do anything when something changes in the directory:

webContainerInstance.fs.watch('/' + pluginData.plugin_dirname, { recursive: true }, (event, filename) => {
	console.log(`file: ${filename} action: ${event}`);
});

But this does run the callback function, but only for items in the root of the directory:

webContainerInstance.fs.watch('/' + pluginData.plugin_dirname, {}, (event, filename) => {
	console.log(`file: ${filename} action: ${event}`);
});

johnstonphilip avatar Sep 04 '24 23:09 johnstonphilip

Hey everyone! :wave:

We landed support for the recursive flag on the @webcontainer/api fs.watch yesterday. :partying_face:

So this means that your examples @johnstonphilip and @dorakadri should no longer report an error saying:

[ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable
 on the current platform, which is being used to run Node.js

Note that if you use fs.watch with the recursive flag inside a node process you will still get the error as our current version of Node (18.20.3) does not support fs.watch on Linux (which WebContainer is an approximation of).

So @rotu, to be able to use ava you'll need to wait until we land Node 20.

@johnstonphilip this seems like a bug. I've created this project: https://stackblitz.com/edit/wc-api-fs-watch, do you think you could fork it and try to reproduce the issue there?

Nemikolh avatar Sep 05 '24 20:09 Nemikolh

@Nemikolh Thanks! I made a fork here that replicated the bug I am seeing:

https://stackblitz.com/edit/wc-api-fs-watch-hqxlvf?file=main.js

johnstonphilip avatar Sep 11 '24 19:09 johnstonphilip

@johnstonphilip, thanks a lot for the reproduction, it helped a lot! :smiley:

This issue should now be resolved. The example you provided works as expected.

I'm going to close this issue, feel free to re-open or open a new one if you run into new issues! Thanks all!

Nemikolh avatar Sep 16 '24 14:09 Nemikolh