首页 > 解决方案 > 如何修复 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。

标签: nativescriptaws-amplifynativescript-angular

解决方案


推荐阅读