3

I am currently using nativescript 6.0.2 to build a cross-platform app and I need to be able to upload files to s3 using aws-cognito authentication to upload.

I have tried installing the javascript aws-sdk using npm install but I am getting these errors before the build.

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

I know that to use aws-sdk with nativescript you need the plugin nativescript-nodeify but the problem is that this plugin is not currently compatible with nativescript 6.0.2.

How would I fix this error or is there any other way I can use the aws-sdk to upload to s3 using cognito?

I know about the nativescript-aws-sdk plugin but that is ONLY for s3 and uses endpoints, access key and secret key when I NEED to use amazon cognito also.

  • `nativescript-nodeify` writes a wrapper around NativeScript APIs to support very few NodeJS APIs like `fs`, `crypto`, etc., I don't think it supports S3 upload as multi part data format is not supported by {N} Http Client / XHR. Try [nativescript-aws-sdk](https://github.com/triniwiz/nativescript-aws-sdk) plugin instead. – Manoj Aug 16 '19 at 17:25
  • @manoj the nativescript-aws-sdk plugin is only for s3 and it doesn't let me use cognito. – user3600496 Aug 16 '19 at 17:37

1 Answers1

1

I ran into this and indeed nativescript-nodeify is Not aligned with recent versions of nativescript (i am using 6.0.2).

I tried to fix them one at a time in my environment and found following solution.

In your webpack.config.js, add following 4 lines in the "node" block.

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

I was stuck at a later point when I was to use aws-amplify for S3/storage APIs, but this should get you moving.