npm install installs vue-element-admin and reports an error npm ERR! -4058 enoent An unknown git error occurred solution

Note: This blog is written word by word by the blogger, which is not easy. Please respect the originality, thank you all!

Problem Description

Many friends, especially those who are completely unfamiliar withnode.js, mostly pull and download projects directly from the warehouse to the local area. The first time they want to start and run the project locally is completely If you don’t know how to start working directly, you will be confused when you encounter an error

For example, when we pull or download the vue-element-admin project from the remote warehouse to the local, use the npm install command to install the packages that the project depends on. At this time Many friends will encounter the following error

npm ERR! code ENOENT
npm ERR! syscall spawn git
npm ERR! path git
npm ERR! errno -4058
npm ERR! enoent An unknown git error occurred
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\Program Files\nodejs\node_cache\_logs\2023-08-08T00_48_42_038Z-debug-0.log

Insert image description here

Cause Analysis

The first thing to do is to understandnpm installWhat does this command mean and what it does? Only by knowing this can we better locate the source of the problem. Many execution command errors should also be analyzed in this way

What is npm install command?

npm install is a command of Node Package Manager (npm) , which is used to install the required dependency packages in the project. It reads the package.json files in the project directory and downloads the defined dependency packages from npm registry. Before using the code of the dependent package in the project, you usually need to run the npm install command first, and then the dependent package will be installed in the node_modules directory.

Git errors you may encounter

Why do you say it's possible? To be honest,npm install when installing project dependency packages, according to the blogger's experience, you may not get this error every time you install it and make sure it is in your system path. , then you Just install packagesgit error Tip, we need to know that npm itself does not need to install git, but if you need to use it when installing certain npmgitgit

Solution

This error is usually caused byGitnot being installed correctly or not configuringPATHenvironment variables. npmRequiredGit while performing an operation, but the required file or path could not be found, hence the "npm err! code enoent npm err! syscall spawn git npm err! path git npm err! errno -4058 npm err! enoent an unknown git error occurred npm err! enoent this is related to npm not being able to find a file. npm err! enoent”

In order to avoid possible Git errors, you can solve them by the following methods:

Install Git:

Please refer to this article by the blogger " The latest GitHub novice tutorial (Windows Git from installation to use) - detailed illustrations

Configure Git environment variables:

After we have installed Git, when we enter on the cmd command terminal, it says that it cannot be found. So you need to configure environment variablesgit

Insert image description here

When the environment variable is not configuredGit, entering where git in the terminal will prompt that the file cannot be found

Insert image description here

Edit system variables—>Path—Enter the path to install Git. The path here is to the cmd directory. For example, your installation directory is a>C:\Program Files\Git, then it isC:\Program Files\Git\cmd

Insert image description here

After completing the environment variable configuration, execute the where git command again in the terminal, and you will see that the system has found the gitexecution directory

where git
git --version

Insert image description here

Note: Restart your computer and execute the npm install command again, all git related problems will be solved

Insert image description here

Guess you like

Origin blog.csdn.net/qq_41782425/article/details/132151752