Closed joshmossas closed 5 months ago
I've identified the cause. For some reason dynamically importing @parcel/watcher
in src/server/watcher.ts
causes a segfault when you try to use the subscribe()
function
If you import subscribe()
from @parcel/watcher
normally the segfault doesn't occur anymore.
So the change I made to get things working looks like this:
// top of file
import { subscribe, type AsyncSubscription } from "@parcel/watcher";
// registering subscription (line 55)
watcher = await subscribe(
devServer.cwd,
... rest
)
I'm aware this fix isn't ideal because we it no longer dynamically imports from @parcel/watcher-wasm
if using @parcel/watcher
fails. But at least it provides a starting point for fixing the issue.
Okay I'm not able to reproduce on MacOS so this seems to be Linux specific.
Hi dear @joshmossas. Can you please try await import("@parcel/watcher")
in a simple test.mjs
file alone to see if can still reproduce?
Lazy loading of watcher is essential for listhen because we don't need it in all paths. We might track this issue from https://github.com/parcel-bundler/watcher or Node.js seems lower level bug.
Okay so it looks like the source of the issue is actually this. https://github.com/parcel-bundler/watcher/issues/170
Listhen is using wildcard ignores by default, which is triggering this bug https://github.com/unjs/listhen/blob/1e73929e0a1d9ec1ce6dd9b6041f19b3e30dcd78/src/server/watcher.ts#L77
You can disregard my comment about lazy loading being the issue. In my fork turns out I accidentally imported @parcel/watcher-wasm
which doesn't have this bug. :sweat_smile:
I've also reverted to using lazy loading in my fork (with @parcel/watcher-wasm
only) and it works.
Thanks for checking upstream 🙏🏼 okay let's track from there then. i will also subscribe to see what happens.
Environment
Reproduction
https://github.com/joshmossas/listhen-watch-segfault
Describe the bug
Running listhen in watch mode causes you to get the following error:
This is true if you use the cli (
listhen ./my-file.ts --watch
) or if you calllistenAndWatch()
directly.Additional context
Downgrading to NodeJS
v20.11.1
causes everything to run normally.I haven't tried to reproduce on other operating systems. So I can only confirm that this is happening in Linux.
Logs
No response