【问题标题】:Karma: proj4 is not a function业力:proj4 不是函数
【发布时间】:2017-03-03 15:24:41
【问题描述】:

真的很奇怪。我已经使用 TeamCity 构建了一个 Angular 应用程序,并尝试将业力测试作为构建任务运行:

ng test

2 个测试失败,抱怨缺少依赖项,恰好是 proj4

单步执行失败的测试,这真的很奇怪。

对 proj4 的调用是按函数进行的(在应用程序和测试中本地工作):

const coords = proj4(sourceProjection, targetProjection, point.toArray());

但在构建服务器上产生proj4 is not a function,但proj4确实存在,但它位于一个名为“default”的属性后面,因此在调试器中

proj4.default(sourceProjection, targetProjection, point.toArray());

有效。

我的意思是wtf!?谁或什么在补充 .default 属性。红润的构建系统!

我已经仔细检查了 angular-cli、npm、node 等都是相同的版本。

FWIW proj4 是通过angular-cli.json 的脚本属性包含在应用程序中的node_module。

【问题讨论】:

  • 嗨。我的真实代码(不是测试)也有同样的问题。你搞清楚了吗?
  • 我有一个类似的问题,在我 webpack 之后它只能通过“默认”属性访问。不知道这里发生了什么,但感谢您提出这个问题,因为它帮助我解决了我的问题。

标签: angular teamcity karma-runner angular-cli proj4js


【解决方案1】:

与包裹捆绑器相同。正如你所说,可以通过例如修复。替换

const proj4 = require("proj4")

const proj4 = require("proj4").default

【讨论】:

    猜你喜欢
    • 2021-05-31
    • 1970-01-01
    • 2020-11-16
    • 2020-05-09
    • 2017-01-31
    • 2016-04-26
    • 1970-01-01
    • 2015-03-04
    • 1970-01-01
    相关资源
    最近更新 更多