-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Fix "Cannot set property closed of" on Node 18 #836
Fix "Cannot set property closed of" on Node 18 #836
Conversation
src/volume.ts
Outdated
// Since Node 18, there is only a getter for '.closed'. | ||
// The first branch mimics other setters from Readable. | ||
// See https://github.com/nodejs/node/blob/v18.0.0/lib/internal/streams/readable.js#L1243 | ||
if (this._readableState && typeof this._readableState.closed === 'boolean') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (this._readableState && typeof this._readableState.closed === 'boolean') { | |
if (typeof this._readableState?.closed === 'boolean') { |
It should be possible to use optional chaining here right?
@G-Rath I addressed your feedback and also realized that I should fix the
Especially because But I can change it, whatever you prefer. |
@G-Rath just a friendly reminder about this PR. |
^^ for this merge request. |
## [3.4.2](v3.4.1...v3.4.2) (2022-05-17) ### Bug Fixes * set `closed` property correct on Node 18 ([#836](#836)) ([d1823e1](d1823e1))
🎉 This PR is included in version 3.4.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@@ -3,7 +3,7 @@ version: 2 | |||
refs: | |||
container: &container | |||
docker: | |||
- image: node:14 | |||
- image: node:18 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to believe that the library should be simultaneously tested on all LTS versions of Node.js in addition to at least the major versions of the recent ones.
Theoretically they all are in active dev, or maintenance, and as such bear the potential to break. If the e2e test suite could be run on all versions, that can act as the first line of defence. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I simply changed this value because I'm not a maintainer/code-owner of this lib and this was the easiest I could do to make sure it works on Node 18.
streamich/memfs#836 This was fixed in 3.4.2
Fixes #828
I'm not an expert on Node internals but from briefly reading the source code, it seems the problem is that
.closed
doesn't have a setter since Node 18 (https://github.com/nodejs/node/blob/v18.0.0/lib/internal/streams/readable.js#L1243).The fix is to check whether
this._readableState.closed
/this._writableState.closed
exists and use it instead ofthis.closed
. This mimics other setters from theReadable
/Writable
class.I also upgraded the node image in CI - to use Node 18.
The test plan is I guess just to see if CI checks pass. I saw #829 and it seems the tests failed there. From my understanding, if my fix is correct, CI checks should pass now. I also ran
yarn test
locally on Node 18.1 and it succeeded.