tinify / tinify-nodejs

Node.js client for the Tinify API.
https://tinypng.com/developers
MIT License
423 stars 74 forks source link

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

Open sabrenda opened 8 months ago

sabrenda commented 8 months ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch tinify@1.7.1 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.

rkoopmans commented 8 months ago

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 commented 8 months ago

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