npm命令运行时报错_npm/cnpm/ng命令运行报错与解决汇总(持续更新中...)

(1) cnpm : 无法加载文件 C:\Users\liy\AppData\Roaming\npm\cnpm.ps1,因为在此系统上禁止运行脚本。

cnpm-v命令报错.png

解决:

在win10 系统中搜索框输入Windos PowerShell,选择管理员身份运行

打开powershell命令行窗口之后,输入set-ExecutionPolicy RemoteSigned

更改权限为A

最后通过 get-ExecutionPolicy命令查看当前的状态

解决.png

(2) The serve command requires to be run in an Angular project, but a project definition could not be found.

ng-serve命令报错.png

分析:根据waring信息来看,应该是本地angular版本与全局angular版本(angular cli 默认安装最新版本)不一致导致的。解决方案为将本地和全局angular版本保持一致即可。

方案一(升版本):修改本地版本和全局版本(最新版本)一致

① 卸载项目当前的angular版本

npm uninstall --save-dev angular-cli

② 清除缓存确保卸载干净(在低版本的nodejs里面清除缓存使用的命令是 npm cache clean)

npm cache verify

③ 安装最新版本

npm install --save-dev @angular/cli@latest

④ 安装/更新依赖

npm install

ng update @angular/cli

⑤ 查看版本

ng version

方案二(降版本):修改全局版本和本地版本一致

① 卸载当前全局版本

npm uninstall -g @angular/cli

② 安装指定版本(waring中提示的版本,也可在项目配置文件中查看)

npm install -g @angular/cli@1.7.4

③ 安装/更新依赖

npm install

④ 查看版本

ng version

全局版本.png

(3) You seem to not be depending on "@angular/core". This is an error.

解决:运行 npm install 来安装或更新依赖

33.png

(4) Error: Cannot find module 'core-js/modules/es6.regexp.constructor'

image1.png

image2.png

image3.png

分析:根据Error信息来看,应该是不识别es6语法所致。

解决:执行命令cnpm install core-js@2即可解决。

(5) npm WARN Local package.json exists, but node_modules missing, did you mean to install?

1.png

解决:输入npm install或 cnpm install命令 后,再次启动npm run dev成功。

成功启动.png

(6) npm installan安装依赖时报错,提醒 stack Error: Can't find Python executable "python", you can set the PYTHON env variable 且 node-sass@4.14.0 postinstall: `node scripts/build.js

找不到python.png

node-sass安装失败.png

解决:卸载当前node-sass版本,并重新安装指定的node-sass版本

卸载node-sass

npm uninstall node-sass

重新安装指定的node-sass版本

npm install node-sass@4.14.0

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值