VS code 安装依赖包出现的一系列报错:node.js
场景:
VS code安装依赖包的一系列报错
问题描述
问题1:VS code使用npm install 安装包的时候,出现 **npm:无法将“npm项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符:1
+npm i
+CategoryInfo:ObjectNotFound:(npm:String) (],CommandNotFoundException
4FullyQualifiedErrorId :CommandNotFoundException**

因为没有安装node.js,所以识别不了,下面安装node.js:
参考https://blog.ZEEKLOG.net/weixin_42182741/article/details/152072795
感谢大佬提供的详细教程!
安装之后,在VS code终端运行npm install,此时出现:
问题2:npm : 无法加载文件 E:\NodeJS\npm.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlin k/?LinkID=135170 中的 about_Execution_Policies。 所在位置 行:1 字符: 1

解决方式为:
解决方法:
1.点击左下角window符号,右键打开菜单,点击PowerShell(管理员)命令窗:

2.在命令窗口输入命令: Set-ExecutionPolicy RemoteSigned,并回车;

3.在执行后的命令后,输入Y,回车即可:

此时回到VS code继续npm install,此时出现问题3: npm ERR! code ENOENT npm ERR! syscall open npm ERR! path /path/to/your/project/package.json npm ERR! errno -2 npm ERR! enoent ENOENT: no such file or directory, open ‘/path/to/your/project/package.json’
报错
解决方式:
发现自己的项目根目录下面还没有package.json文件,创建新的package.json文件,在VS code终端运行
npm init 此时出现package.json文件
再次运行npm install安装包,又出现问题4:
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path D:\自己的路径\node_cache_cacache\tmp\712dc97e
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, open ‘D:\IT_base\node18\node_cache_cacache\tmp\712dc97e’
npm ERR! [Error: EPERM: operation not permitted, open ‘D:\IT_base\node18\node_cache_cacache\tmp\712dc97e’] {
npm ERR! errno: -4048,
npm ERR! code: ‘EPERM’,
npm ERR! syscall: ‘open’,
npm ERR! path: ‘D:\:自己的路径\node_cache\_cacache\tmp\712dc97e’
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:\自己的路径\node_cache_logs
npm ERR! You can rerun the command with --loglevel=verbose to see the logs in your terminal

解决方法:
给这两三文件加上的权限不够,把这些文件的权限都开启起来。

方法为:
1.选择node_cache文件,右键点击属性

2.点击安全,并编辑
3.勾上完全控制,点击应用,确定。

剩下的两个文件夹也是一样,把权限给足够,我是将node_cache和node_global两个文件的权限加上就可以了,不行的可以将三个文件的权限都加上