Closed
Description
When I install version 0.27.1 of replicate-javascript library in react-native project, I get error like below.
Node Version: 18.18.0
The package at "node_modules/replicate/lib/util.js" attempted to import the Node standard library module "node:crypto". It failed because the native React runtime does not include the Node standard library
When I install version 0.26.0, it does not give any error. The problem seems to be related to the improvements made in the newly released version 0.27.1.
How can we find a solution for this?
Update:
I don't use webhooks in the project. I applied a temporary patch like below, but I haven't tested it for webhooks!
diff --git a/node_modules/replicate/lib/util.js b/node_modules/replicate/lib/util.js
index 48d7563..6ffc9bd 100644
--- a/node_modules/replicate/lib/util.js
+++ b/node_modules/replicate/lib/util.js
@@ -1,4 +1,4 @@
-const crypto = require("node:crypto");
+const CryptoJS = require("crypto-js");
const ApiError = require("./error");
@@ -74,10 +74,7 @@ async function validateWebhook(requestData, secret) {
const secretBytes = Buffer.from(signingSecret.split("_")[1], "base64");
- const computedSignature = crypto
- .createHmac("sha256", secretBytes)
- .update(signedContent)
- .digest("base64");
+ const computedSignature = CryptoJS.HmacSHA256(secretBytes, signedContent).toString(CryptoJS.enc.Base64);
const expectedSignatures = signature
.split(" ")
diff --git a/node_modules/replicate/package.json b/node_modules/replicate/package.json
index 098bb3a..3ff64b6 100644
--- a/node_modules/replicate/package.json
+++ b/node_modules/replicate/package.json
@@ -33,7 +33,8 @@
"test": "jest"
},
"optionalDependencies": {
- "readable-stream": ">=4.0.0"
+ "readable-stream": ">=4.0.0",
+ "crypto-js":"4.2.0"
},
"devDependencies": {
"@biomejs/biome": "^1.4.1",
Metadata
Metadata
Assignees
Labels
No labels