aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.07k stars 574 forks source link

Unable to get configuration from AppConfig on browser #2587

Closed abel30567 closed 3 years ago

abel30567 commented 3 years ago

Describe the bug

@aws-sdk/client-appconfig is referencing tslib@2.0.0 and that package does not implement __spreadArray. When loading the package on a React app I see the following warnings

"export '__spreadArray' was not found in 'tslib'

I am not able to fetch the App Configs

Your environment

SDK version number

@aws-sdk/client-appconfig@3.21.0

Is the issue in the browser/Node.js/ReactNative?

Browser

Details of the browser/Node.js/ReactNative version

Chrome: 91.0.4472.164
node -v
v10.22.0

Steps to reproduce

export const getAppConfigs = async (
  code: String,
): Object => {
  try {
    const Client = new AppConfigClient({
      region: <REGION>,
      credentials: {
        accessKeyId: <ACCESS_KEY>,
        secretAccessKey: <SECRET_KEY>
      }
    });
    const command = new GetConfigurationCommand({
      Application: `App-${code}`,
      ClientId: `App-${code}-Client`,
      Configuration: "AppConfig",
      Environment: "Dev"
    });
    const response = await Client.send(command); // Fails here
    let parsedConfigs = JSON.parse(
      String.fromCharCode.apply(null, response.Content)
    );

  } catch (error) {
    throw error;
  }
};

Observed behavior

When I send a request I get the following error

TypeError: Object(...) is not a function
    at MiddlewareStack.js:110
    at Array.reduce (<anonymous>)
    at getMiddlewareList (MiddlewareStack.js:108)
    at Object.resolve (MiddlewareStack.js:190)
    at GetConfigurationCommand../node_modules/@aws-sdk/client-appconfig/dist/es/commands/GetConfigurationCommand.js.GetConfigurationCommand.resolveMiddleware (GetConfigurationCommand.js:64)
    at AppConfigClient../node_modules/@aws-sdk/client-appconfig/node_modules/@aws-sdk/smithy-client/dist/es/client.js.Client.send (client.js:10)
    at _callee3$ (Auth.js:122)

Expected behavior

Expected to receive the AppConfig blob response.

Screenshots

According to browser dev tools the MiddlewareStack.js:110 depends on __spreadArray image

Additional context

I replaced tslib from @aws-sdk/client-appconfig@3.21.0 manually with version tslib@2.3.0 and the following warning went away.

"export '__spreadArray' was not found in 'tslib'

However, the request kept on failing when trying to fetch the AppConfigs

AllanZhengYP commented 3 years ago

The __spreadArray is only available after tslib 2.1.0, however, most of the SDK package targets tslib ^2.0.0. I will put up a fix to bump up the tslib version. We should have bump up the tslib everytime we upgrade our TypeScript version. Luckily TypeScript team posted the compatibility table recently: https://github.com/microsoft/tslib/issues/148

AllanZhengYP commented 3 years ago

As a short-term workaround, you can specify "tslib": "^2.3.0"(or other version >= 2.1.0) in your dependencies. It will be picked up by v3 SDK

abel30567 commented 3 years ago

I got the warning for the __spreadArray to go away but I am getting CORS error when I try to fetch the AppConfig from the browser

AllanZhengYP commented 3 years ago

Hi @abel30567, Can you open a separate issue for it? We will address it separately.

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.