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

[Bug?]: Yarns patching of the fs module subtly breaks in node >20.5.1 #5951

Closed
1 task
danieltroger opened this issue Nov 7, 2023 · 6 comments · Fixed by #5961
Closed
1 task

[Bug?]: Yarns patching of the fs module subtly breaks in node >20.5.1 #5951

danieltroger opened this issue Nov 7, 2023 · 6 comments · Fixed by #5961
Labels
bug Something isn't working

Comments

@danieltroger
Copy link

danieltroger commented Nov 7, 2023

Self-service

  • I'd be willing to implement a fix

Describe the bug

On node versions above 20.5.1, swc-node stops working with the following cryptic error:

node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^
TypeError [ERR_INVALID_RETURN_PROPERTY_VALUE]: Expected array buffer, or typed array to be returned for the "source" from the "transformSource" function but got undefined.
    at new NodeError (node:internal/errors:406:5)
    at assertBufferSource (node:internal/modules/esm/translators:84:9)
    at stringify (node:internal/modules/esm/translators:94:3)
    at createCJSModuleWrap (node:internal/modules/esm/translators:219:12)
    at ModuleLoader.commonjsStrategy (node:internal/modules/esm/translators:297:10) {
  code: 'ERR_INVALID_RETURN_PROPERTY_VALUE'
}

Node.js v20.9.0

This is due to the node js worker which deals with something related to custom esm modules has a reference to the unpatched readFileSync function from the fs module, see swc-project/swc-node#736 (comment)

To reproduce

Follow the steps outlined in this issue report: swc-project/swc-node#736 (comment)

Environment

System:
  OS: macOS 14.0 (23A344)
  CPU: Apple M1 Max
Binaries:
  Node: v20.9.0
  Yarn: 4.0.1-git.20231104.hash-afacd23

Additional context

No response

@danieltroger danieltroger added the bug Something isn't working label Nov 7, 2023
@0618
Copy link

0618 commented Nov 10, 2023

I have the same issue.

Environment:

  System:
    OS: macOS 13.6
    CPU: (12) arm64 Apple M2 Pro
  Binaries:
    Node: 20.9.0 -
    Yarn: 4.0.1 -

@vhpoet
Copy link

vhpoet commented Nov 10, 2023

Same here

Environment:

  System:
    OS: macOS 14.0
    CPU: Apple M1 Max
  Binaries:
    Node: 21.1.0
    Yarn: 4.0.1

@arcanis
Copy link
Member

arcanis commented Nov 10, 2023

This is a Node bug which they don't see as a bug 🙁 (nodejs/node#39513)

@danieltroger
Copy link
Author

danieltroger commented Nov 10, 2023

@arcanis thanks for the link. Holy guacamole, what a situation. I have two questions:

  1. Why does this first start breaking swc-node above node 20.5.0? From the issue you linked it appears to be quite an old issue
  2. Is there no way to work around this via loaders or some other node feature? Is there a way of using swc-node that doesn't run into this issue?

@arcanis
Copy link
Member

arcanis commented Nov 10, 2023

I'm not sure unfortunately. I've been pointed out to another issue on the Node.js Slack channels which, together with the first one, may be why this problem just appeared: nodejs/node#50435.

arcanis pushed a commit that referenced this issue Nov 14, 2023
…5961)

**What's the problem this PR addresses?**

nodejs/node#48842 changed it so that our fs
patch is loaded after the internal translators so ESM importing named
CJS exports in loaders doesn't work.

Fixes #5951

**How did you fix it?**

Updated our ESM loader patching to target the `fs` bindings used
internally.

**Checklist**
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have set the packages that need to be released for my changes to
be effective.
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
merceyz added a commit that referenced this issue Nov 14, 2023
…5961)

**What's the problem this PR addresses?**

nodejs/node#48842 changed it so that our fs
patch is loaded after the internal translators so ESM importing named
CJS exports in loaders doesn't work.

Fixes #5951

**How did you fix it?**

Updated our ESM loader patching to target the `fs` bindings used
internally.

**Checklist**
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have set the packages that need to be released for my changes to
be effective.
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.

(cherry picked from commit 6e920f9)
@lizthegrey
Copy link
Contributor

@arcanis thanks for the link. Holy guacamole, what a situation. I have two questions:

  1. Why does this first start breaking swc-node above node 20.5.0? From the issue you linked it appears to be quite an old issue
  2. Is there no way to work around this via loaders or some other node feature? Is there a way of using swc-node that doesn't run into this issue?

This will be fixed in Node 20.11.0, per nodejs/node#50435 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants
@lizthegrey @vhpoet @arcanis @danieltroger @0618 and others