lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.28k stars 1.3k forks source link

Sharp build failure due to NewOrCopy not found in Napi::Buffer<char> #4253

Closed KMJ-007 closed 1 week ago

KMJ-007 commented 1 week ago

Build Errors with Sharp Library

During the build process, the following errors were encountered when building the Sharp library:

Copy../metadata.cc: In member function 'virtual void MetadataWorker::OnOK()':
../metadata.cc:237:46: error: 'NewOrCopy' is not a member of 'Napi::Buffer<char>'
   237 |         info.Set("exif", Napi::Buffer<char>::NewOrCopy(env, baton->exif, baton->exifLength, sharp::FreeCallback));
       |                                              ^~~~~~~~~
../metadata.cc:240:45: error: 'NewOrCopy' is not a member of 'Napi::Buffer<char>'
   240 |         info.Set("icc", Napi::Buffer<char>::NewOrCopy(env, baton->icc, baton->iccLength, sharp::FreeCallback));
       |                                             ^~~~~~~~~
../metadata.cc:243:46: error: 'NewOrCopy' is not a member of 'Napi::Buffer<char>'
   243 |         info.Set("iptc", Napi::Buffer<char>::NewOrCopy(env, baton->iptc, baton->iptcLength, sharp::FreeCallback));
       |                                              ^~~~~~~~~
../metadata.cc:246:45: error: 'NewOrCopy' is not a member of 'Napi::Buffer<char>'
   246 |         info.Set("xmp", Napi::Buffer<char>::NewOrCopy(env, baton->xmp, baton->xmpLength, sharp::FreeCallback));
       |                                             ^~~~~~~~~
../metadata.cc:250:31: error: 'NewOrCopy' is not a member of 'Napi::Buffer<char>'
   250 |           Napi::Buffer<char>::NewOrCopy(env, baton->tifftagPhotoshop,
       |                               ^~~~~~~~~
make: *** [sharp-linux-x64.target.mk:173: Release/obj.target/sharp-linux-x64/metadata.o] Error 1

Error Summary

The errors indicate that the NewOrCopy method is not a member of the Napi::Buffer<char> class, which is causing the build to fail.


Reproduction Steps

  1. Install Node.js v22.10.0 and Bun v1.1.0.
  2. Run the following build command:
    pnpm install sharp
  3. Observe the build failure with the Sharp library.

Environment

lovell commented 1 week ago

What is the complete output of running npm install --verbose --foreground-scripts sharp in an empty directory? (The issue template asked for this information but it was ignored/deleted.)

KMJ-007 commented 1 week ago

What is the complete output of running npm install --verbose --foreground-scripts sharp in an empty directory? (The issue template asked for this information but it was ignored/deleted.)



npm verbose cli /opt/render/project/nodes/node-22.10.0/bin/node /opt/render/project/nodes/node-22.10.0/bin/npm
npm info using npm@10.9.0
npm info using node@v22.10.0
npm verbose title npm install sharp
npm verbose argv "install" "--loglevel" "verbose" "--foreground-scripts" "sharp"
npm verbose logfile logs-max:10 dir:/opt/render/.cache/_logs/2024-11-06T05_11_07_433Z-
npm verbose logfile /opt/render/.cache/_logs/2024-11-06T05_11_07_433Z-debug-0.log
npm http fetch GET 200 https://registry.npmjs.org/@ai-sdk%2fgoogle 1891ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/zod 50ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@ai-sdk%2fopenai 1480ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@axiomhq%2fpino 1718ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@deepgram%2fsdk 1498ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@fal-ai%2fserverless-client 1487ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@fastify%2fcookie 1485ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@fastify%2fcors 87ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@fastify%2fhelmet 237ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@fastify%2fjwt 461ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@fastify%2foauth2 1481ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@fastify%2frate-limit 1305ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@fastify%2fsecure-session 1490ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@fastify%2fsensible 1488ms (cache miss)

``sh
lovell commented 1 week ago

Please provide the complete output when run in an empty directory. (The partial output you've provided includes details of packages unrelated to sharp.)

KMJ-007 commented 1 week ago

i am using mono repo with pnpm workspace, i am not able to get the proper logs which you are asking for using npm command

can you provide pnpm command which i can try, and for empty dir i don't have direct access to machine at the moment, i am using http://render.com for deploying my service,

i know you also can't do anything without any proper logs, but from my end i am able to provide you this information, if you can guide me i am able to help here better

lovell commented 1 week ago

The partial logs shown here suggest you're trying to compile sharp from source against a globally-installed libvips. Is that what you intended? If not, e.g. perhaps Render has pre-installed libvips, then you can set the SHARP_IGNORE_GLOBAL_LIBVIPS environment variable at install time to skip this logic.