angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.72k stars 11.98k forks source link

Migrating to the new build system @aws-sdk/lib-storage Upload is not working any more #27771

Closed mohammed-elrais closed 2 weeks ago

mohammed-elrais commented 3 months ago

Command

build, serve

Is this a regression?

The previous version in which this bug was not present was

Before Migrating to the new build system

Description

I am trying to upload images to AWS but because of the Migrating to the new build system it is not working anymore

Minimal Reproduction

import { Upload } from "@aws-sdk/lib-storage";
import { S3Client } from "@aws-sdk/client-s3";

  const parallelUploads3 = new Upload({
    client:  new S3Client({}),
    params: { Bucket, Key, Body },
  });
  parallelUploads3.on("httpUploadProgress", (progress) => {
    console.log(progress);
  });

parallelUploads3.done() .then(
                (data) => {
                   console.log(data)
                },
                (err: any) => {
                    console.log(err)
                },
            );

Exception or Error

TypeError: Cannot read properties of undefined (reading 'done')
    at getChunkStream.js:5:5
    at Generator.next (<anonymous>)
    at resume (chunk-CDW57LCT.js?v=b9e9dd30:100:27)
    at chunk-CDW57LCT.js?v=b9e9dd30:106:63
    at new ZoneAwarePromise (zone.js:1425:21)
    at it.<computed> [as next] (chunk-CDW57LCT.js?v=b9e9dd30:106:38)
    at Upload.<anonymous> (Upload.js:130:9)
    at Generator.next (<anonymous>)
    at chunk-CDW57LCT.js?v=b9e9dd30:90:61
    at new ZoneAwarePromise (zone.js:1425:21)

Your Environment

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/

Angular CLI: 17.3.8
Node: 18.13.0
Package Manager: npm 8.19.4
OS: darwin x64

Angular: 17.3.10
... animations, cdk, common, compiler, compiler-cli, core, forms
... material, material-moment-adapter, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1703.8
@angular-devkit/build-angular   17.3.8
@angular-devkit/core            17.3.8
@angular-devkit/schematics      17.3.8
@angular/cli                    17.3.8
@angular/google-maps            16.2.14
@schematics/angular             17.3.8
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.6

Anything else relevant?

    "dependencies": {
        "@angular-material-extensions/password-strength": "^16.0.0",
        "@angular/animations": "^17.3.7",
        "@angular/cdk": "^17.3.7",
        "@angular/common": "^17.3.7",
        "@angular/compiler": "^17.3.7",
        "@angular/core": "^17.3.7",
        "@angular/forms": "^17.3.7",
        "@angular/google-maps": "^16.2.14",
        "@angular/material": "^17.3.7",
        "@angular/material-moment-adapter": "^17.3.7",
        "@angular/platform-browser": "^17.3.7",
        "@angular/platform-browser-dynamic": "^17.3.7",
        "@angular/router": "^17.3.7",
        "@aws-sdk/client-s3": "^3.574.0",
        "@aws-sdk/credential-providers": "^3.574.0",
        "@aws-sdk/lib-storage": "^3.574.0",
        "@ngx-translate/core": "^14.0.0",
        "@ngx-translate/http-loader": "^7.0.0",
        "@tinymce/tinymce-angular": "^8.0.0",
        "angular-calendar": "^0.31.1",
        "angular-user-idle": "^4.0.0",
        "bootstrap": "^4.6.2",
        "file-saver": "^2.0.5",
        "moment": "^2.30.1",
        "ng2-pdf-viewer": "^10.0.0",
        "ngx-captcha": "^13.0.0",
        "ngx-image-cropper": "^7.2.1",
        "ngx-mask": "^16.4.2",
        "rxjs": "^7.4.0",
        "tslib": "^2.6.2",
        "xlsx": "^0.17.5",
        "zone.js": "~0.14.5"
    },
cpt-cyrilcomor commented 1 month ago

Hello, having the exact same issue here with angular version 17 Any investigations undergoing ?

kloc823 commented 2 weeks ago

hello, how is it going?

eXpertise7 commented 2 weeks ago

@alan-agius4 Confirmed. This is actual issue. I think it's a critical priority.

eXpertise7 commented 2 weeks ago

@mohammed-elrais @cpt-cyrilcomor @kloc823 Has anyone of you made issue request at @aws-sdk? I can't find it.

kloc823 commented 2 weeks ago

hi @eXpertise7, i didn't raise issue to aws since aws-sdk v3/v2 work good in my other (angular/react) projects

alan-agius4 commented 2 weeks ago

I have looked into the issue and it appears to be caused by esbuild, as I was able to replicate the problem using the Angular CLI.

index.js

import { Upload } from "@aws-sdk/lib-storage";
import { S3Client } from "@aws-sdk/client-s3";

const text = "This is some sample text to stream.";

const readableStream = new ReadableStream({
  start(controller) {
    controller.enqueue(new TextEncoder().encode(text));
    controller.close();
  },
});

const parallelUploads3 = new Upload({
  client: new S3Client({}),
  params: { Body: readableStream },
});

parallelUploads3.on("httpUploadProgress", (progress) => {
  console.log(progress);
});

parallelUploads3.done().then(
  (data) => {
    console.log(data);
  },
  (err) => {
    console.log(err);
  }
);

esbuild.config.js

export default {
  platform: 'browser',
  bundle: true,
  entryPoints: ['./index.js'],
  supported: {
    'async-await': false,
  },
}

Commands

$ esbuild > output.js
$ node output.js
Cannot read properties of undefined (reading 'done')
    at output.js:16472:123
    at Generator.next (<anonymous>)
    at resume (output.js:56:31)
    at output.js:61:67
    at new Promise (<anonymous>)
    at it.<computed> [as next] (output.js:61:42)
    at Upload.<anonymous> (output.js:16728:97)
    at Generator.next (<anonymous>)
    at output.js:46:63
    at new Promise (<anonymous>)

Based on this, there is nothing actionable from our end at this point. This seems to be an issue with esbuild rather than Angular.