0

I try to run expo optimize and it says it requires sharp-cli.

So I install sharp-cli as it directs.

And then it gives me the same error.

(first step described above is left out)

$ npm install -g sharp-cli@1.10.0
/Users/TuzMacbookPro2017/.npm-global/bin/sharp -> /Users/TuzMacbookPro2017/.npm-global/lib/node_modules/sharp-cli/bin/cli.js
+ sharp-cli@1.10.0
updated 1 package in 24.632s
$ expo optimize
This will overwrite the original assets.
Optimizing assets...
Optimizing ./assets/electro-icon-1024.png
This command requires version 1.10.0 of `sharp-cli`. 
You can install it using `npm install -g sharp-cli@1.10.0`. 

For prerequisites, see: https://sharp.dimens.io/en/stable/install/#prerequisites
Set EXPO_DEBUG=true in your env to view the stack trace.

This was happening before and I was able to fix it by restarting my terminal, or something like that. No such luck this time.

Also if it helps, expo-cli tells me there's a new version when I run an expo command, no matter how many times I install the new version. Similar problem, it seems.

Installing with yarn global add didn't fix it either.

Jonathan Tuzman
  • 11,568
  • 18
  • 69
  • 129

1 Answers1

1

Can you try installing sharp-cli@1.10.0 locally instead?

npm i -S sharp-cli@1.10.0

If that doesn't work I would try cleaning out your cache and trying again:

npm cache clean --force

Hopefully that helps!

Nathan
  • 7,853
  • 4
  • 27
  • 50
  • Thanks. That second command warns, "I sure hope you know what you're doing." I don't. Should I take any precautions before doing this? – Jonathan Tuzman Jul 11 '19 at 00:23
  • @JonathanTuzman I would try installing the sharp-cli locally first then rerunning expo optimize. npm cache clean will delete the data stored in npm's cached folder. Alternatively, you can run npm cache verify and if no issues are reported then the integrity of your cached data is fine. Cheers – Nathan Jul 11 '19 at 14:07
  • I tried the local install with no luck. I'll try cleaning and verifying the cache and report back. Thanks for the help. – Jonathan Tuzman Jul 11 '19 at 16:29
  • Whelp, after cleaning and verifying, trying `npm install -g sharp-cli@1.10.0` gives me a `cb() never called` error, along with an `EACCES permission denied` error, so I ran it as `sudo`, and `expo optimize` still doesn't work. – Jonathan Tuzman Jul 11 '19 at 18:31
  • what's the stack trace? – Nathan Jul 11 '19 at 18:47
  • Check that your npm prefix location is on your system's path. If you installed the module globally and it's still not recognized that could be the reason: https://stackoverflow.com/questions/57298227/scss-bundle-command-not-found/57298713#57298713 – Nathan Aug 07 '19 at 22:44
  • same problem here, i tried all the suggestions here and expo optimize throws the same error. :/ – Caio Mar Aug 14 '19 at 16:26
  • `expo optimize` has been removed from expo command line interface. I'm not familiar with sharp-cli otherwise i'd chime in, however... I have had issues related to permissions being denied while installing globally. After taking a look at more closely I found that some packages were owned by admin, some staff, some root, some me. Rather that foul with it at all I just manuall force deleted the directory and when reinstalled after clearing cache, etc, it installed perfecto. – Adriano Michael Apr 04 '20 at 07:32
  • You can do `npx expo-optimize` now @AdrianoMichael – wobsoriano Apr 30 '22 at 16:44