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

Cannot load cacert.pem #30

Open
philiprenich opened this issue Sep 6, 2021 · 3 comments
Open

Cannot load cacert.pem #30

philiprenich opened this issue Sep 6, 2021 · 3 comments

Comments

@philiprenich
Copy link

Hello,
I am getting the following error within AWS Lambda.

2021-09-06T05:46:28.634Z undefined ERROR Uncaught Exception {"errorType":"Error","errorMessage":"ENOENT: no such file or directory, open 'node_modules/tinify/lib/tinify/../data/cacert.pem'","code":"ENOENT","errno":-2,"syscall":"open","path":"node_modules/tinify/lib/tinify/../data/cacert.pem","stack":["Error: ENOENT: no such file or directory, open 'node_modules/tinify/lib/tinify/../data/cacert.pem'"," at Object.openSync (fs.js:462:3)"," at Object.readFileSync (fs.js:364:35)"," at eval (webpack://[*****]/./node_modules/tinify/lib/tinify/Client.js?:11:17)"," at Object.209977 (/var/task/handler.js:1:57787456)"," at __webpack_require__ (/var/task/handler.js:1:67436561)"," at ...

It appears that the cacert.pem file cannot be found and loaded. Searching around I found this SO question that seems to say that the path setup is incorrect.

Client.js doesn't use path.join() as the answer suggestions it should.

const data = fs.readFileSync(`${__dirname}/../data/cacert.pem`).toString();

My code is loading Tinify with a simple import, which seems to be the only difference, but I'm not sure it would matter?

import tinify from 'tinify'

Thank you for the help!

@philiprenich
Copy link
Author

Following the route from the stack overflow answer and using path.join worked. However, this was a direct change to the compiled asset once the build was done, so is not a viable solution. Hopefully a code change here could solve it.

I'm curious why it has an issue in AWS Lambda functions and what specifically causes it because it's a showstopper that would be very noticeable if it was widespread. I'm not familiar enough with AWS's environment to know what is different about our set up.

@SurfJordan
Copy link

I'm having the same issue @philiprenich, I was wondering if you found a solution?

@rkoopmans
Copy link
Contributor

The problem is indeed with the webpack output not including the cacert.pem bundle. The path.join / stackoverflow solution did not make a difference for me but it might work with a file loader of some sort. Sadly my webpack knowlege is not good enough to come up with a suggestion here.

I got it working by coping the node_modules code into my AWS functions container, but I understand that defeats the purpose of using a bundler.

An alternative solution would be to include the cacert.pem as a json array (javascript) so it will be automatically packaged, it is not very pretty but would resolve the issue.

It is important to note that the Tinify API client is not intended for use by the frontend (browser) but only in backend code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants