【问题标题】:How to use the aws-sdk in nativescript 6.0?如何在 nativescript 6.0 中使用 aws-sdk?
【发布时间】:2019-12-22 23:37:00
【问题描述】:

我目前正在使用 nativescript 6.0.2 构建跨平台应用程序,我需要能够使用 aws-cognito 身份验证将文件上传到 s3 进行上传。

我尝试使用 npm install 安装 javascript aws-sdk,但在构建之前我收到了这些错误。

ERROR in ../node_modules/aws-sdk/lib/credentials/process_credentials.js
Module not found: Error: Can't resolve 'child_process' in '/Users/nabhanmaswood/Desktop/Computer/Quadrant2/wowza-nativescript-plugin/demo-angular/node_modules/aws-sdk/lib/credentials'
 @ ../node_modules/aws-sdk/lib/credentials/process_credentials.js 2:11-35
 @ ../node_modules/aws-sdk/lib/node_loader.js
 @ ../node_modules/aws-sdk/lib/aws.js
 @ ./app/home/home.component.ts
 @ ./app/home/home.module.ts
 @ ../$$_lazy_route_resource lazy namespace object
 @ ../node_modules/@angular/core/fesm5/core.js
 @ ./app/app.module.ts
 @ ./main.ts

ERROR in ../node_modules/aws-sdk/lib/publisher/index.js
Module not found: Error: Can't resolve 'dgram' in '/Users/nabhanmaswood/Desktop/Computer/Quadrant2/wowza-nativescript-plugin/demo-angular/node_modules/aws-sdk/lib/publisher'
 @ ../node_modules/aws-sdk/lib/publisher/index.js 2:12-28
 @ ../node_modules/aws-sdk/lib/node_loader.js
 @ ../node_modules/aws-sdk/lib/aws.js
 @ ./app/home/home.component.ts
 @ ./app/home/home.module.ts
 @ ../$$_lazy_route_resource lazy namespace object
 @ ../node_modules/@angular/core/fesm5/core.js
 @ ./app/app.module.ts
 @ ./main.ts

ERROR in ../node_modules/xml2js/lib/parser.js
Module not found: Error: Can't resolve 'timers' in '/Users/nabhanmaswood/Desktop/Computer/Quadrant2/wowza-nativescript-plugin/demo-angular/node_modules/xml2js/lib'
 @ ../node_modules/xml2js/lib/parser.js 17:17-34
 @ ../node_modules/xml2js/lib/xml2js.js
 @ ../node_modules/aws-sdk/lib/xml/node_parser.js
 @ ../node_modules/aws-sdk/lib/node_loader.js
 @ ../node_modules/aws-sdk/lib/aws.js
 @ ./app/home/home.component.ts
 @ ./app/home/home.module.ts
 @ ../$$_lazy_route_resource lazy namespace object
 @ ../node_modules/@angular/core/fesm5/core.js
 @ ./app/app.module.ts
 @ ./main.ts

我知道要将 aws-sdk 与 nativescript 一起使用,您需要插件 nativescript-nodeify,但问题是该插件当前与 nativescript 6.0.2 不兼容。

我将如何解决此错误,或者有什么其他方法可以使用 aws-sdk 使用 cognito 上传到 s3?

我知道 nativescript-aws-sdk 插件,但这仅适用于 s3,并且在我还需要使用 amazon cognito 时使用端点、访问密钥和密钥。

【问题讨论】:

  • nativescript-nodeify 围绕 NativeScript API 编写了一个包装器,以支持很少的 NodeJS API,例如 fscrypto 等,我认为它不支持 S3 上传,因为多部分数据格式是{N} Http Client / XHR 不支持。改用nativescript-aws-sdk 插件。
  • @manoj nativescript-aws-sdk 插件仅适用于 s3,它不允许我使用 cognito。

标签: amazon-s3 nativescript aws-sdk amazon-cognito


【解决方案1】:

我遇到了这个问题,nativescript-nodeify 确实与最新版本的 nativescript 不一致(我使用的是 6.0.2)。

我尝试在我的环境中一次修复它们并找到以下解决方案。

在您的 webpack.config.js 中,在“node”块中添加以下 4 行。

        node: {
            "child_process": "empty",
            "dgram": "empty",
            "net": "empty",
            "crypto": true,
        },

我后来在将 aws-amplify 用于 S3/存储 API 时遇到了困难,但这应该会让你动起来。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-26
    • 2020-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多