1 Cannot set property ‘errorHandler’ of undefined

前端报错

Uncaught TypeError: Cannot set property ‘errorHandler’ of undefined

样例分析

errorHandler 是vue.config对象上的属性
但在使用Vue.config未初始化为对象,导致操作报错。

app.config.errorHandler = err => {
    /* 处理错误 */
    console.log('组件出现问题',err)
}
  • 1.
  • 2.
  • 3.
  • 4.

解决方法

初始化Vue.config为对象

app.config = {};
app.config.errorHandler = err => {
    /* 处理错误 */
    console.log('组件出现问题',err)
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

2 UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token ‘??=’

前端报错

(node:18376) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token ‘??=’

样例分析

逻辑空赋值(??=)是ES2021的语法,node v15.0.0以上才支持逻辑空赋值(??=)的语法

解决方法

使用nvm切换15以上版本的node,成功解决