tinify-nodejs icon indicating copy to clipboard operation
tinify-nodejs copied to clipboard

how to optimize so that next js can see it after deployment in vercel?

Open sabrenda opened this issue 1 year ago • 2 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/tinify/lib/tinify/Client.js b/node_modules/tinify/lib/tinify/Client.js
index 09b1eb7..e9d4064 100644
--- a/node_modules/tinify/lib/tinify/Client.js
+++ b/node_modules/tinify/lib/tinify/Client.js
@@ -7,7 +7,7 @@ const proxyAgent = require("proxying-agent");
 const package_json_1 = require("../../package.json");
 const tinify_1 = require("../tinify");
 const boundaries = /-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----\n/g;
-const data = fs.readFileSync(`${__dirname}/../data/cacert.pem`).toString();
+const data = fs.readFileSync(`${process.cwd()}/cacert.pem`).toString();
 class Client {
     /** @internal */
     constructor(key, appIdentifier, proxy) {

This issue body was partially generated by patch-package.

sabrenda avatar Feb 13 '24 10:02 sabrenda

Hi Sabrenda,

Thanks for the patch. I understand that __dirname can be '/' on development (https://github.com/vercel/next.js/discussions/14341). Is that why it was not working for you?

The approach of getting the current working dir (process.cwd()) might break the library for other people. We will have to implement a solution that works for both.

rkoopmans avatar Feb 14 '24 12:02 rkoopmans

Would you be able to share with me how you are using the Tinify client with Vercel? That would help us reproduce the issue.

rkoopmans avatar Feb 14 '24 14:02 rkoopmans