Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New @aws-sdk/client-sns package version is creating invalid Javascript: "if (input.AWSAccountId?.length === 0) {" #4144

Closed
3 tasks done
wangytangy opened this issue Nov 3, 2022 · 2 comments
Assignees
Labels
closed-for-staleness p2 This is a standard priority issue

Comments

@wangytangy
Copy link

wangytangy commented Nov 3, 2022

Checkboxes for prior research

Describe the bug

We use aws-sdk/client-sns to trigger email alerts for updates in our web application. Today we began getting an error from the node_modules when the package was upgraded during a deployment. We believe the new package version that broke our app was "version": "3.160.0" according to our package-lock.json. We also tried using the most updated package version @3.202.0 but got the same error.

Our app runs Kubernetes on EKS and our AWS credentials are set automatically so we don't think that was the problem.

Pinning the @aws-sdk/client-sns package to "3.43.0" removed the error and our app began working again after re-deployment. However we are stuck with the old version.

SDK version number

@aws-sdk/client-sns/@3.202.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

12

Reproduction Steps

import { SNSClient, PublishCommand } from '@aws-sdk/client-sns';

export default {
  initialize (app) {
    if (!this.s3) {
      this.s3 = new aws.S3();
      debug('Connected to Amazon S3.');
    }
    if (!this.sns) {
      this.sns = new SNSClient({ region: 'us-east-1' }); // we think this is where the bug starts
      debug('Connected to Amazon SNS.');
    }
  }
}

Observed Behavior

When we deployed the app, we encountered this breaking error. It seems like invalid Javascript was created. A "?" character was added to the key "AWSAccountId" somehow.

(node:35) UnhandledPromiseRejectionWarning: /var/node/atlas/node_modules/@aws-sdk/client-sns/dist-cjs/protocols/Aws_query.js:2801

        if (input.AWSAccountId?.length === 0) {
                               ^
SyntaxError: Unexpected token '.'
    at compileFunction (<anonymous>)
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Object.require.extensions.<computed> [as .js] (/var/node/atlas/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/var/node/atlas/node_modules/@aws-sdk/client-sns/dist-cjs/commands/AddPermissionCommand.js:8:21)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Object.require.extensions.<computed> [as .js] (/var/node/atlas/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
(node:35) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:35) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.```

### Expected Behavior

We expected the ```new SNSClient({ region: 'us-east-1' });``` function to work with the most updated @aws-sdk/client-sns package.

### Possible Solution

We pinned the @aws-sdk/client-sns package version to "3.43.0" for now and it currently has no problems with our stack. However that means we are stuck with the old package version.

### Additional Information/Context

_No response_
@wangytangy wangytangy added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 3, 2022
@yenfryherrerafeliz yenfryherrerafeliz self-assigned this Nov 3, 2022
@yenfryherrerafeliz yenfryherrerafeliz added the p1 This is a high priority issue label Nov 3, 2022
@yenfryherrerafeliz
Copy link
Contributor

When we deployed the app, we encountered this breaking error. It seems like invalid Javascript was created. A "?" character was added to the key "AWSAccountId" somehow.

Hi @wangytangy, thanks for opening this issue. The character "?" is a feature known as optional chaining in JS, and it just prevent an error about reading a property from an undefined element, for example if "input.AWSAccountId" is undefined or null then instead of an error, undefined will be returned. So, the reason why you may be getting this error is because optional chaining is not supported by node 13 and below, so that you should consider to use node 14 and above in order to have this error gone, and also node 12 is not longer supported by the AWS SDK for JavaScript. Information can be found here.

Thanks!

@yenfryherrerafeliz yenfryherrerafeliz added closing-soon This issue will automatically close in 4 days unless further comments are made. p2 This is a standard priority issue and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. p1 This is a high priority issue labels Nov 4, 2022
@github-actions github-actions bot added closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Nov 9, 2022
@github-actions github-actions bot closed this as completed Nov 9, 2022
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closed-for-staleness p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

2 participants