tinify / tinify-nodejs

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

TypeScript Import error #44

Closed sdack-cloud closed 8 months ago

sdack-cloud commented 1 year ago
let tinify1 = require('tinify')
OR
import tinify from 'tinify'

tinify.key = "123";

ERROR

Reason: TypeError: fs.readFileSync is not a function

nodejs v15.14.0 npm 7.7.6 "tinify": "^1.7.1", "vue": "^2.6.11", "typescript": "~4.1.5",

sdack-cloud commented 1 year ago

image

sdack-cloud commented 1 year ago

image

sdack-cloud commented 1 year ago

Using uni app

vue create -p dcloudio/uni-preset-vue uni-type-demo
rkoopmans commented 1 year ago

Hey sdack-cloud,

The tinify-nodejs client is not build or meant to be run in a frontend app. The fs.ReadFileSync is not available in a browser context, but is used in the tinify code.

In case you use a frontend framework with API views, use the tinify client only in the server code.

The problem with running Tinify in frontend code, is that your API key will be leaked in the user browser., therefore using the API directly in a browser context is not made possible.