globalexpo

Why expo-cli must be installed globally?


The official way of working with expo-cli is to install it globally, see https://docs.expo.io/get-started/installation/#installing-expo-cli:

Installing Expo CLI

# Install command line tools
npm install --global expo-cli

However, I never found any explanation about why it is supposed to be global (other than that this simplifies the initial expo init command). To my thinking, having a global package undermines the whole idea behind npm and local node_modules. Essentially, expo-cli is a direct dependency of the project. It's used for running the dev version with expo start and also for creating production builds.

Different versions of expo-cli will work differently, they may even expect different values in app.config.ts. That means it's not safe to upgrade expo-cli globally for one project and then return working with an older project which has been created and maintained with an older version of (global) expo-cli.

None of this would have happened if expo-cli were a normal local project dependency like expo (the SDK package).

So, my question is: is there a real reason for keeping expo-cli global? What do I lose if I move it to local project dependencies? How come Expo documentation never even mentions such option?


Solution

  • In Expo SDK 46 they introduced a new “Local Expo CLI”.

    However, this was possibly because of the fact that if you don't have or delete the "node_modules" directory, you can't reinstall with "expo install".