这个错误代码通常时由于权限不足所导致,例如执行npm link

image-20240622133024358

详细报文如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
npm ERR! code EPERM
npm ERR! syscall symlink
npm ERR! path D:\hexo\plugins\hexo-footer-plugin
npm ERR! dest D:\Environment\nodejs\node_global\node_modules\hexo-footer-plugin
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, symlink 'D:\hexo\plugins\hexo-footer-plugin' -> 'D:\Environment\nodejs\node_global\node_modules\hexo-footer-plugin'
npm ERR! [Error: EPERM: operation not permitted, symlink 'D:\hexo\plugins\hexo-footer-plugin' -> 'D:\Environment\nodejs\node_global\node_modules\hexo-footer-plugin'] {
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'symlink',
npm ERR! path: 'D:\\hexo\\plugins\\hexo-footer-plugin',
npm ERR! dest: 'D:\\Environment\\nodejs\\node_global\\node_modules\\hexo-footer-plugin'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! Log files were not written due to an error writing to the directory: D:\Environment\nodejs\node_cache\_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

以管理员身份运行即可

image-20240622133143109

也有可能说缓存原因导致,清除缓存即可

1
npm cache clean --force

或者

1
npm cache verify

npm cache clean --forcenpm cache verify 是 npm 提供的用于管理缓存的命令。下面是对这两个命令的详细介绍:

npm cache clean --force

  • 功能:该命令用于强制清除 npm 缓存。
  • 使用场景:当你遇到缓存问题,比如缓存的包损坏或过时,导致安装或更新包时出现问题,可以使用此命令来清除缓存。
  • 注意事项:使用 --force 选项会强制执行清除操作,即使 npm 认为缓存是有效的。这可能会导致缓存中的所有数据被删除。
  • 命令示例
    1
    npm cache clean --force

npm cache verify

  • 功能:该命令用于验证 npm 缓存中的内容是否完整和有效。
  • 使用场景:当你怀疑缓存中的某些包可能损坏或不完整时,可以使用此命令来验证缓存的健康状况。
  • 注意事项:该命令会检查缓存中的每个包,确保它们没有损坏,并且与远程仓库中的包一致。
  • 命令示例
    1
    npm cache verify

总结

  • npm cache clean --force 用于强制清除 npm 缓存。
  • npm cache verify 用于验证 npm 缓存中的内容是否完整和有效。

在实际使用中,如果你遇到与缓存相关的问题,可以先尝试使用 npm cache verify 来检查缓存的健康状况,如果问题依然存在,再考虑使用 npm cache clean --force 来清除缓存。

参考

NPM错误-ERRNO -4048