繁体   English   中英

如何替换 npm 中的凉亭包 jsTimezoneDetect

[英]How can I replace the bower package jsTimezoneDetect in npm

我正在尝试替换我的 repo 中的 bower,但在替换这个包时遇到了问题: "jsTimezoneDetect": "1.0.4" 替换它的建议包是"jstimezonedetect": "^1.0.6" 我正在使用这个包,如下所示:

var missionJoin = {
    timeZoneId : jstz.determine().name()
};

然而,这给了我这个错误:

ReferenceError: Can't find variable: Intl in node_modules/jstimezonedetect/dist/jstz.js (line 124)
get_from_internationalization_api@node_modules/jstimezonedetect/dist/jstz.js:124:22
determine@node_modules/jstimezonedetect/dist/jstz.js:412:67
joinMission@app/scripts/controllers/robo.profile.ProfileServiceCtrl.js:1:27975
test/specs/robo.profile.profileServiceCtrl.spec.js:151:27
<Jasmine>

这个包没有任何依赖关系,错误似乎来自包本身的问题。 我在这里做错了吗? 有没有其他人遇到过类似的问题? 任何帮助将不胜感激!

对于将来可能会遇到此问题的任何人,以下是我解决此问题的方法:

https://github.com/iansinnott/jstz的最后一段找到

export function findTimeZone() {
  const oldIntl = window.Intl
  try {
    window.Intl = undefined
    const tz = jstz.determine().name()
    window.Intl = oldIntl
    return tz
  } catch (e) {
    // sometimes (on android) you can't override intl
    return jstz.determine().name()
  }
}

var missionJoin = {
    timeZoneId : findTimeZone()
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM