安装npm react-navigation时Git submodule错误求助
Hey there, let’s work through this frustrating error you’re getting when running npm install --save react-navigation. The "git-submodule appears broken" message usually points to issues with how Git is configured on your system, even if you think you’ve added the path to environment variables. Here are some actionable steps to fix it:
1. Double-Check Your Git Environment Variable Path
It sounds like you added a Git path to your environment variables, but it might be pointing to the wrong location (like a Microsoft-included Git from Visual Studio instead of the standalone Git installation).
- Open Command Prompt and run
git --version. If this throws an error, your Path is misconfigured. - The correct path should point to the bin and cmd folders of your standalone Git installation. Typical paths are:
C:\Program Files\Git\binC:\Program Files\Git\cmd
- Add these paths to your System Environment Variables > Path, then restart your terminal (and any IDEs like VS Code) to apply the changes.
2. Repair or Reinstall Git
If your Git path is correct but you still get the submodule error, the git-submodule component might be corrupted:
- Uninstall your current Git installation from Control Panel.
- Download the latest version of Git (the standalone installer, not the one bundled with other tools).
- During installation, make sure to select the option to "Add Git to your PATH" (usually marked as the recommended choice).
3. Clear NPM Cache and Retry Installation
Corrupted NPM cache can sometimes interfere with package installations that rely on Git submodules:
- Run this command to clear the cache:
npm cache clean --force - Then try installing react-navigation again:
npm install --save react-navigation
4. Try Using Yarn Instead (Alternative)
If NPM still gives you trouble, Yarn often handles Git-related installations more smoothly:
- If you don’t have Yarn installed, run
npm install -g yarnfirst. - Then install the package with:
yarn add react-navigation
Quick Note on react-navigation Versions
Just a heads-up: the react-navigation package you’re trying to install is the older v4 version. If you’re starting a new project, you might want to use the newer @react-navigation/native suite instead, but that’s separate from fixing the current Git error.
内容的提问来源于stack exchange,提问作者Anjali

