Reasons and solutions for npm installation reporting no such file or directory

The company uses an intranet, so the npm download is also installed through a service of the company as a proxy.
When installing dependencies, there will always be a period of time when there is a problem with the installation dependencies.
As shown in the picture:
insert image description here
It was able to be installed normally a few days ago, but today it suddenly reported the error of no such file or directory .
The location of the report is under the .stagin folder of node_modules, as shown in the figure: insert image description here
In fact, the .stagin folder will only appear when the dependencies are installed, and it will disappear automatically after the installation is successful. However, during the installation process, the dependencies are all in the .stagin folder. After the installation is successful, they are directly placed in the node_modules directory.
View all errors reported no such file or directory , nothing more than appearing on individual dependencies such as core and echarts.

For example: the dependency I wrote myself (I know the content of the packaged file, so I use it as an example), has already been installed in the .stagin file (no missing files), so no such file or directory error is
not reported
insert image description here
I believe the same is true for most dependencies.
But individual dependencies, such as echarts reporting this error:
insert image description here
expand this folder and find nothing, then it is normal for npm to report that the file in echarts cannot be found.

reason

From the analysis of the appeal process, it is roughly guessed that it is related to the npm service agent (npm default agent service, cnpm Taobao mirror agent, other agents, etc.) when installing dependencies. There are basically two reasons:

  1. By locking the dependent package-lock.json to install, it is possible that the resolved address in the package-lock.json that needs to be downloaded cannot be found in the service of the npm proxy being used, resulting in failure to download the corresponding dependent file.
  2. There is a problem with the service proxied by npm. The service you proxied does not have this dependency at all.

Solution:

  • If it is caused by reason 1, just delete package-lock.json and reinstall the dependencies. It's just that package-lock.json will also be updated with your latest npm service proxy.
  • If it is reason 2, there is a problem with the service of the npm proxy, you can try to switch the service proxy to the previous service recorded in package-lock.json (you can check the involved field in the dependency). If you can't switch the proxy (like I can only use the npm mirror proxy specified by the company's intranet), you can only ask someone to deal with the npm service problem or wait for it to heal itself.

Guess you like

Origin blog.csdn.net/weixin_43589827/article/details/120708226