nativescript - 如何修复 nativescript 中的“TypeError:process.hrtime 不是函数”?
问题描述
我正在使用 aws-amplify 构建一个 nativescript (+Angular) 应用程序。特别是在使用 aws-amplify 的 S3 Storage API 时,我收到以下错误:
AWSS3Provider - get signed url error TypeError: process.hrtime is not a function. (In 'process.hrtime()', 'process.hrtime' is undefined)
我正在使用以下polyfills
(window as any).global = window;
(window as any).process = {
env: { DEBUG: undefined },
};
在我的代码中,我检查进程是否未定义。
if(typeof process !== 'undefined') {
Storage.get('fileassets/asset.txt')
.then(result => alert(result))
.catch(err => alert(err));
} else {
alert("process is undefined");
}
没有引发警报,但似乎本机代码 S3Provider 依赖于 process.hrtime,在 nativescript 非 {N} 环境中无法解决
我希望 aws-amplify API 能够成功执行,因为它无法控制它来避免调用 process.hrtime。
解决方案
推荐阅读
- linux-kernel - 再次导出相同的 GPIO 时删除 GPIO 文件夹
- haskell - Haskell 从 IO 域获取值
- c++ - 关于成员重载中使用 std::move() 的问题
- kotlin - 通过辅助构造函数初始化 Kotlin 数据类的 val 属性
- javascript - 如何在 Angular 6 项目中绘制谷歌柱形图?
- javascript - 回调函数、辅助函数和包装函数有什么区别?
- javascript - 如何按值过滤 JavaScript 对象?
- go - 类型转换为相似类型
- c# - 使用 Noda Time 获取给定偏移量的时区列表(以分钟为单位)
- java - 将始终执行 CompletableFuture 回调