NodeJS: Illegal instruction (core dumped) Error after using sharp library

Viewed 1393

When I add this piece of code from sharp package (that is a image processing package):

await sharp(req.file.path)
    .resize(500)
    .jpeg({ quality: 50 })
    .toFile(path.resolve(req.file.destination, “resized”, filename));

I get this error:

Illegal instruction (core dumped)

When I remove it, everything is ok. I’m very confused. What is wrong with that code?

1 Answers

Through my conversation with @Tomalak, it seems that the latest version of sharp is not compatible with my CPU:

Theres nothing wrong with your code. That's a bug in sharp - apparently it tries to use CPU instructions that are not supported on your CPU. Try an older version of sharp. – Tomalak

I tried a couple of older versions. The latest version that works for me is 0.27.2. you can install it using this command:

npm i sharp@0.27.2

I also opened an issue on their GitHub page: https://github.com/lovell/sharp/issues/2723#issue-894046354

My environment (npx envinfo --binaries --system):

System:
  OS: Linux 5.4 Linux Mint 20 (Ulyana)
  CPU: (2) x64 Pentium(R) Dual-Core  CPU      E5300  @ 2.60GHz
  Memory: 172.51 MB / 3.84 GB
  Container: Yes
  Shell: 3.2.2 - /usr/bin/fish
Binaries:
  Node: 10.19.0 - /usr/bin/node
  npm: 7.6.1 - /usr/local/bin/npm
Related