鸿蒙 ohpm 的异常报错

        解压安装 ohpm ,  进入 command-line-tools/ohpm/bin 目录执行 ohpm -v , 一直提示未初始化异常:ERROR: ohpm has not been initialized yet. Execute the init script to initialize it first.  google搜索发现都是让配置环境变量、执行init脚本,尝试后都无法解决

问题排查:执行 node pm-cli.js 查看报错明细

/workData/util/harmony/command-line-tools-mac/ohpm/lib/tools/posh/enum.js:1

"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ParameterList=exports.StyleType=void 0;const r=e(require("lodash"));var t,o,n,a,u;!function(e){e[e.Black=0]="Black",e[e.Red=1]="Red",e[e.Green=2]="Green",e[e.Yellow=3]="Yellow",e[e.Blue=4]="Blue",e[e.Magenta=5]="Magenta",e[e.Cyan=6]="Cyan",e[e.White=7]="White"}(t||(t={})),function(e){e[e.Bold=1]="Bold",e[e.Underline=4]="Underline",e[e.Inverse=7]="Inverse"}(o||(o={})),function(e){e[e.Foreground=30]="Foreground",e[e.Background=40]="Background",e[e.ForegroundBright=90]="ForegroundBright",e[e.BackgroundBright=100]="BackgroundBright"}(n||(n={})),function(e){e[e.Bold=22]="Bold",e[e.Foreground=39]="Foreground",e[e.Background=49]="Background",e[e.Underline=24]="Underline",e[e.Inverse=27]="Inverse"}(a||(a={})),function(e){e[e.Color=0]="Color",e[e.Decoration=1]="Deco


TypeError: Object.keys(...).filter(...).flatMap is not a function

    at Object.<anonymous> (/workData/util/harmony/command-line-tools-mac/ohpm/lib/tools/posh/enum.js:1:1037)

    at Module._compile (internal/modules/cjs/loader.js:778:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

    at Module.load (internal/modules/cjs/loader.js:653:32)

    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)

    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

    at Module.require (internal/modules/cjs/loader.js:692:17)

    at require (internal/modules/cjs/helpers.js:25:18)

    at Object.<anonymous> (/workData/util/harmony/command-line-tools-mac/ohpm/lib/tools/posh/index.js:1:97)

    at Module._compile (internal/modules/cjs/loader.js:778:30)

发现:flatMap方法在Object.keys(...).filter(...)返回的数组上不存在。搜了下flatMap方法是ES2019中加入了JavaScript标准库,也就是 Node.js从v11.15.0和v12.0.0版本开始支持flatMap方法。问题出现的原因可能是 node 版本太低了,查看当前 node 版本

@ZBMAC-caf471e75 bin % node -v                        

v10.17.0

尝试升级到高版本,方便管理node版本切换,我这里引入了 n 管理器 

sudo npm i -g n  #安装 n

sudo n 18.14.1   # 使用 n 安装 18 版本

执行 n 可以查看 当前已安装的版本,选择切换也可以直接执行 n use xx 切换版本

升级后再次执行 ,成功

bin % ohpm -v                        
1.5.1

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值