Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
Fix building for Cloudflare Nitro preset
Browse files Browse the repository at this point in the history
It seems that Rollup node-resolve module doesn't properly deal with
trailing slashes, causing it to thing that `string_decoder` is a
built-in Node.js dependency and attempt to import it from `unenv`, which
will obviously fail, because `string_decoder` is not, in fact, a Node.js
dependency, but an individual dependency of `readable-stream`.

This adds a small patch for `[email protected]` dependency, which
removes the leading slash, which seems to fix the builds.

This probably should be reported to relevant developers (Rollup
node-resolve plugin or Nitro?).
  • Loading branch information
brawaru committed Jun 14, 2024
1 parent 34fd9d2 commit 7b788ff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"packageManager": "[email protected]",
"pnpm": {
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
}
}
}
22 changes: 22 additions & 0 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 3af95cb2dbf1e9fa93d261b030b0b090df507ff7..376e6979c13264d80d96e045ddbba5258d219373 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -169,7 +169,7 @@ function ReadableState(options, stream) {
this.decoder = null;
this.encoding = null;
if (options.encoding) {
- if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
+ if (!StringDecoder) StringDecoder = require('string_decoder').StringDecoder;
this.decoder = new StringDecoder(options.encoding);
this.encoding = options.encoding;
}
@@ -325,7 +325,7 @@ Readable.prototype.isPaused = function () {

// backwards compatibility.
Readable.prototype.setEncoding = function (enc) {
- if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
+ if (!StringDecoder) StringDecoder = require('string_decoder').StringDecoder;
this._readableState.decoder = new StringDecoder(enc);
this._readableState.encoding = enc;
return this;
9 changes: 6 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b788ff

Please sign in to comment.