首页 > 解决方案 > Safari ReferenceError:找不到变量:Tmpo(= 纯 js 类)

问题描述

我编写了一个小型 Angular 应用程序,它在我的 assets/js 文件夹中使用了一个简单的 js 类。一切都在我的本地环境中完美运行(ng-serve)。当我构建和部署我的应用程序(ng build --prod)时,我得到一个ReferenceError: Can't find variable: Tmpo。但是,仅在 Safari 中...

此处提供代码:https ://github.com/flukso/flukso.github.io 此处提供站点:https ://flukso.github.io

我的 js 类 (tmpo.js)

$.ajaxSetup({
  timeout: 10 * 60 * 1000, // msecs
  cache: false
})

class Tmpo {
  constructor(uid, token, debug = false) {
     ...
  }
  ...
}

angular.json

...
"scripts": [
              "src/assets/js/tmpo.js"
            ]
...

在我的组件中:

import ...

declare var Tmpo: any;

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

    export() {

        const tmpo = new Tmpo(null, this.token.value, false);
        ...
    }
}

标签: angular

解决方案


试试这个,前几天遇到了类似的问题:

ng build --prod --aot --service-worker --base-href ./


推荐阅读