无法安装任何 NPM 包,错误 4058

Nic*_*las 10 javascript node.js npm gruntjs

我正在尝试在我的项目上安装 Grunt。它曾经完美地工作,但现在由于某种原因,它没有。每次我尝试安装 Grunt 时,都会出现此错误:

npm ERR! path C:\irrelevent\path\project\node_modules\ansi-styles
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\irrelevent\path\project\node_modules\ansi-styles' -> 'C:\irrelevent\path\project\.ansi-styles.DELETE'
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!     C:\Users\Me\AppData\Roaming\npm-cache\_logs\2018-04-03T00_52_10_105Z-debug.log
Run Code Online (Sandbox Code Playgroud)

奇怪的是,丢失的包每次都改变。
我尝试验证缓存,删除node_modules文件夹,使用--force. 卸载 NPM 和 NodeJS,重启我的电脑。没有机会。
出于安全原因,我不得不格式化我的计算机,我使用了项目文件夹而不是Roaming文件夹,我不知道这是否有影响,但自从我重新安装 NPM 后应该不会。

我不确定这是否有帮助,但这是我的 package.json

{
 "name": "project",
 "version": "2.1.0",
 "repository": "project-2.0",
 "devDependencies": {
   "grunt": "^1.0.2",
   "grunt-cli": "^1.2.0",
   "grunt-contrib-concat": "~1.0.1",
   "grunt-contrib-copy": "^1.0.0",
   "grunt-contrib-cssmin": "~2.0.0",
   "grunt-contrib-jshint": "~1.1.0",
   "grunt-contrib-uglify": "~2.2.0",
   "grunt-contrib-watch": "~1.0.0",
   "grunt-html-build": "^0.7.1",
   "grunt-real-favicon": "^0.2.2"
 },
 "dependencies": {
   "angular-bootstrap-colorpicker": "^3.0.31",
   "angularjs-geolocation": "^0.1.3",
   "sprintf-js": "^1.1.1"
 }
}
Run Code Online (Sandbox Code Playgroud)

小智 18

尝试以下步骤:

  • 删除 package-lock.json并再次运行 NPM。
  • 确保没有其他 node.js 进程正在运行(检查任务管理器)
  • 如果您使用的是 Visual Studio 代码,请将其关闭并npm install再次尝试运行。
  • 如果所有其他方法都失败,请重新启动计算机。

请参阅此处的线程:https : //github.com/npm/npm/issues/17444


Chr*_*her 8

在使用 时npx create-next-app,我们收到此错误,指出无法使用目录上的 lstat,因为它不存在:

C:\someDirectory\> npx create-next-app@latest
npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path %userprofile%\AppData\Roaming\npm
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, lstat '%userprofile%\AppData\Roaming\npm'
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!     %userprofile%\AppData\Local\npm-cache_logs\[TimeStamp]-debug-0.log
Run Code Online (Sandbox Code Playgroud)

上述解决方案没有帮助,只需要npm%appdata%.

安装程序只是检查它,但没有创建它,因此引发了错误。


小智 6

您不应该忘记转到项目文件夹,cd "nameofproject"然后就"npm start"可以工作了。


fvl*_*den 6

对我来说,原因是 Dropbox(我的 NodeJS 项目位于 Dropbox 文件夹深处)。我暂停了同步,npm install再试一次,安装没有错误。然后我当然恢复了同步。