-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
Chokidar chokes on options that are explicitely set to "undefined" #1394
Comments
I am experiencing this same issue, preventing me from upgrading to Chokidar v4. |
Why would you set EXPLICIT option to undefined? Simply don't pass it. |
Some consumer packages seem to not properly clean up the options before passing. So for them, if they see their tests fail after updating, they might just revert back. |
It’s breaking release. We’ve removed legacy code. Consumers can easily do this on their own. |
@Fuzzyma in your particular error (interval is undefined), where did it originate from? Just curious of if we're being too strict at the point we do whatever type check it is that's happening |
@paulmillr I know that and I am also in no way demanding that you change the code. @43081j I came across this when updating webpack/webpack-dev-server#5374. Ofc I could easily fix this in their codebase but I wanted to make minimal changes to make review easier and merge more likely. Chokidar v4 is in most cases a drop in replacement if the consumer didnt use globs. Not allowing undefined as options (which worked before) makes it less that // EDIT: It is also way easier to pass in an option with a ternary when allowing undefined: // undefined allowed
{
someOption: someCondition ? true : undefined
}
// undefined not allowed
{
...(someCondition ? { someOption: true } : undefined)
} // EDIT 2: I would also say that the types reflect what I am saying. Because Lines 49 to 54 in 5e6daaa
|
i understand all of that, im just trying to find out where the error came from in the source what line exactly in chokidar threw? you might just be covering up some overly strict type check we're doing, by allowing undefined at the top level |
They do their own config parsing and seem to introduce undefined there. Must be somewhere here: https://github.com/webpack/webpack-dev-server/blob/09f6f8eb46abce836acbc1b8c892e348106c924e/lib/Server.js#L875 In particular for interval they check if its not undefined. But if none of the conditions match (because interval and poll wasnt passed), it returns nothing = undefined: EDIT: I just realized you were talking about chokidar and not webpack-dev-server. Stacktrace:
Line 333 in 69c115a
|
makes sense so we have a few options:
@paulmillr if we did option 2, it goes from this: const opts = {interval: DEFAULT_INTERVAL, ...userOptions}; to this: const opts = {
interval: userOptions.interval ?? DEFAULT_INTERVAL
} for every option it is true this will make upgrading easier, at the cost of us introducing more code. what are your thoughts? i think my opinion is that it won't be much code for us to add, so maybe its worth it to help with people upgrading |
I would be happy to provide a PR so you can weight the actual changes required. I also want to reiterate, that passing undefined to any option is currently backed by the typings that are public to the consumer since optional parameters allow undefined by definition. So you probably will end up getting reports for the same issue again and again |
that's true (unless if its easy enough, a PR would help and we can review 👍 |
Main upgrade points is lack of globs (harder filtering), lack of native fsevents on macos (resource limits). i would suggest to add an utility function in your webpack code that would clean the options before passing them to chokidar. Once some time passes and you’re fine with the upgrade (some users aren’t), we can consider it. I don’t want to add unnecessary code for users who don’t upgrade in the end. |
@paulmillr well technically I even removed a line. Its really not much code (#1396) |
I'll add my 2 cents that I think this would be nice to handle on the chokidar side. I generally expect undefined and missing properties be handled in the same manner. It's just nicer as a consumer of the library to have less to worry about |
This has to be done because of an issue on chokidars site: paulmillr/chokidar#1394
Describe the bug
Chokidar v4 doesnt clean up the passed options. Setting an option to explicit
undefined
will make node throw.Versions (please complete the following information):
To Reproduce:
Steps to reproduce the behavior. Include filename and chokidar config.
Ideally prove a problem by isolating and making it reproducible with a very short sample program, which you could paste here:
Expected behavior
It should filter out undefined values so that chokidars defaulst are used instead (which doesnt happen because the explicit undefined overwrites the default when spreading):
chokidar/src/index.ts
Lines 361 to 377 in 5e6daaa
Additional context
I was in the process of testing the feasability to update to v4 in webpack/webpack-dev-server#5368.
However, all watch-tests fail with the error
TypeError: The "interval" argument must be of type number. Received undefined
.So either chokidar was cleaning up options in v3 or something else than Nodes native watcher was used.
In any case it is an unexpected breaking change.
I am aware that v4 was a major version bump but this seems to be a minor thing that could be adapted easily to make upgrading to v4 even easier.
Changing the above code to this would solve the problem:
The text was updated successfully, but these errors were encountered: