Promise.then 不是仅在服务器上的函数错误

Promise.then is not a function error only on server

我是 运行 下面的本地代码,它工作正常但在服务器上我有这个错误:

Promise.then is not a function

let promise = null;
  if (this.fileUrl) {
    promise = this.pdfJS.getDocument(this.fileUrl);
  }
  else if (this.base64FileData) {
    const pdfData = atob(this.base64FileData);
    promise = this.pdfJS.getDocument({ data: pdfData });
  }
  console.log('pretty');
  console.log(promise);
  
  promise.then(function (docObj) {
    console.log('promistest');
    console.log(docObj);
    this._loadingEnd();
    this.renderPages(docObj);
  }, this._onDocumentLoadError.bind(this)
);

.getDocument 返回的对象不是 Promise,但它有一个 属性 叫做 promise

因此

let promise;
if (this.fileUrl) {
    promise = this.pdfJS.getDocument(this.fileUrl).promise;
} else if (this.base64FileData) {
    const pdfData = atob(this.base64FileData);
    promise = this.pdfJS.getDocument({ data: pdfData }).promise;
} else {
    promise = Promise.reject('invalid state');
    // this will be handled by `this._onDocumentLoadError.bind(this)`
}
console.log('pretty');
console.log(promise);
promise.then(function (docObj) {
    console.log('promistest');
    console.log(docObj);
    this._loadingEnd();
    this.renderPages(docObj);
}, this._onDocumentLoadError.bind(this));