署后生产环境报Uncaught (in promise) TypeError: Cannot read property 'catch' of undefin

1,019 阅读1分钟

Vue 署后生产环境报Uncaught (in promise) TypeError: Cannot read property 'catch' of undefin

项目在 Dev 环境没有问题,部署上生产环境出现报错。

TypeError: Cannot read properties of undefined (reading 'catch')
    at jt.d.a.push

push 方法一般都 vue-router 引起的。

解决

打开 vue.config.js

const cdn = {
  css: [],
  js: [
    'https://lib.baomitu.com/vue/2.6.10/vue.min.js',
    // 'https://lib.baomitu.com/vue-router/3.0.3/vue-router.min.js',
    'https://lib.baomitu.com/vuex/3.1.0/vuex.min.js',
    'https://lib.baomitu.com/axios/0.19.0/axios.min.js',
    'https://lib.baomitu.com/js-cookie/2.2.1/js.cookie.min.js',
    'https://lib.baomitu.com/moment.js/2.24.0/moment-with-locales.min.js'
  ]
}

const externals = {
  vue: 'Vue',
  // 'vue-router': 'VueRouter',
  vuex: 'Vuex',
  axios: 'axios',
  'js-cookie': 'Cookies',
  moment: 'moment'
}

使用 npm 下载的 vue-router ,不使用 cdn,问题解决。