【问题标题】:Typescript+AngularJS+Webpack modules without default export没有默认导出的 Typescript+AngularJS+Webpack 模块
【发布时间】:2017-10-26 01:09:19
【问题描述】:

我正在使用 Webpack 将 AngularJS 与 Typescript 捆绑在一起(建议使用默认设置 here),并且我不能包含没有默认导出的模块,例如 ui-bootstrap。 ui-router 等模块没有这样的问题,因为它们的类型提到了默认导出。

JS 代码有效:

import * as angular from 'angular';
import router from 'angular-ui-router';
import uibootstrap from 'angular-ui-bootstrap';

angular.module('app', [uirouter, uibootstrap]);

但是 Typescript 中的相同代码(目标:es6,模块:es6,所有设置与 webpack 指南中提到的相同)会报错:

模块“node_modules/@types/angular-ui-bootstrap/index”没有默认导出。

使用angular.module('app', [uirouter, 'ui.bootstrap']); 会引发“未找到“ui.bootstrap”错误。

【问题讨论】:

    标签: angularjs typescript webpack bootstrap-ui


    【解决方案1】:

    您可以在 tsconfig.json 中将 allowSyntheticDefaultImports 设置为 true 以继续导入 import uibootstrap from 'angular-ui-bootstrap';,就像 angular-ui-bootstrap 具有默认导出一样。

    "compilerOptions": {
        "allowSyntheticDefaultImports": true
    }
    

    【讨论】:

    • 这似乎是正确的解决方案,但它仍然没有导入库,使“ui.route”包含在我的角度模块中不起作用。
    【解决方案2】:

    似乎使用简单的import 'angular-ui-router' 就可以了。

    【讨论】:

      猜你喜欢
      • 2021-12-22
      • 2016-05-15
      • 1970-01-01
      • 2019-09-16
      • 2016-11-11
      • 2019-12-29
      • 2021-11-24
      • 2017-03-18
      • 2021-01-09
      相关资源
      最近更新 更多