Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: fsevents.watch is not a function #18728

Closed
7 tasks done
mutantcornholio opened this issue Nov 21, 2024 · 5 comments
Closed
7 tasks done

TypeError: fsevents.watch is not a function #18728

mutantcornholio opened this issue Nov 21, 2024 · 5 comments

Comments

@mutantcornholio
Copy link

Describe the bug

fsevents@~2.3.3 is an optional dependency for vite, and vite can run fine without it.
However, if some other package adds fsevents@1, vite breaks:

file:///Users/cornholio/dev/tmp/vite-bug/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:43399
  const stop = fsevents.watch(path, callback);
                        ^

TypeError: fsevents.watch is not a function
    at createFSEventsInstance (file:///Users/cornholio/dev/tmp/vite-bug/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:43399:25)
    at setFSEventsListener (file:///Users/cornholio/dev/tmp/vite-bug/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:43455:16)
    at FsEventsHandler._watchWithFsEvents (file:///Users/cornholio/dev/tmp/vite-bug/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:43659:18)
    at FsEventsHandler.initWatch (file:///Users/cornholio/dev/tmp/vite-bug/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:43735:23)
    at FsEventsHandler._addToFsEvents (file:///Users/cornholio/dev/tmp/vite-bug/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:43824:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v22.6.0

Reproduction

probably not reproducible on linux, as fsevents is a mac package

Steps to reproduce

npm init
# remixd depends on [email protected], which depends on fsevents@^1.2.7
npm install --save vite @remix-project/remixd

System Info

node v22.6.0
npm 10.9.0
macOS 14.7.1

Used Package Manager

npm

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Nov 21, 2024

Isn't this more of a bug in the package manager where it's not installing or providing the correct version of fsevents for Vite?

@mutantcornholio
Copy link
Author

mutantcornholio commented Nov 21, 2024

Ideally, yes.
It can be solved on package manager level, and I think yarn's PnP shouldn't be susceptible, for example.
I wouldn't get my hopes up about npm fixing it though anytime soon. It's just the way node_modules work, and I think a lot of code in the industry actually expects it to work like that.

UPD: wait a second... I was under impression that vite's using fsevents directly (as it lists fsevents in its optionalDependencies), but it looks like it uses fsevents via chokidar instead? Probably should be directed to chokidar then..
I even found an (unfortunately closed) issue there paulmillr/chokidar#1180

@bluwy
Copy link
Member

bluwy commented Nov 22, 2024

I wouldn't get my hopes up about npm fixing it though anytime soon. It's just the way node_modules work, and I think a lot of code in the industry actually expects it to work like that.

Why not? npm is not giving us the right version based on the semver range we've specified and this looks like a legitimate bug. Is this already reported on npm or other package managers?

About chokidar, I doubt they'll make any fix soon as v4 already removed fsevents. We're still on v3 which uses it because there's regressions in v4 that were not ready yet.

I feel like it's better to place the effort into fixing the source of the issue than patching or adding workarounds.

@mutantcornholio
Copy link
Author

After running the repro with --verbose, I see that it actually fails to compile [email protected]:

npm info run [email protected] install node_modules/fsevents node install.js
npm info run [email protected] install node_modules/rollup/node_modules/fsevents node-gyp rebuild
npm info run [email protected] install node_modules/vite/node_modules/fsevents node-gyp rebuild
npm info run [email protected] install { code: 1, signal: null }
npm verbose reify failed optional dependency /Users/cornholio/dev/tmp/2/node_modules/rollup/node_modules/fsevents
npm info run [email protected] install { code: 1, signal: null }
npm verbose reify failed optional dependency /Users/cornholio/dev/tmp/2/node_modules/vite/node_modules/fsevents

I think it might be related to npm/cli#4859

@sapphi-red
Copy link
Member

I also think that this should be fixed on the package manager side.
In addition, fsevents@2 was released 6 years ago so I assume there won't be many users encountering this.

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Dec 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants