Aws-sdk-js: Warning while bundling with esbuild

Created on 25 Jun 2020  Â·  6Comments  Â·  Source: aws/aws-sdk-js

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
I recently switched to using https://github.com/evanw/esbuild to bundle some of my javascript lambdas & libs which include aws-sdk, when bundling I receive the following warning

node_modules/aws-sdk/lib/xml/node_parser.js:142:32: warning: Comparison using the === operator here is always false
  if (keys.length === 0 || keys === ['$']) {

Specifically, https://github.com/aws/aws-sdk-js/blob/master/lib/xml/node_parser.js#L142

Does x === ['$'] ever return true?

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

If on Node.js, are you running this on AWS Lambda?
Both Lambda & Nodejs

Details of the browser/Node.js version
v14.4.0

SDK version number
2.699.0 & 2.704.0

To Reproduce (observed behavior)

yarn add aws-sdk esbuild
echo "require('aws-sdk')" > index.js
npx esbuild --bundle index.js --platform=node --outdir=dist 

Expected behavior
bundled without warnings

Screenshots
N/A

Additional context
N/A

bug

Most helpful comment

@ajredniwja I think this is a issue with the node_parser.js and not esbuild.

Since === compares the identity of objects, === [anything] will never equal true

Some examples

['$'] === ['$'] // false

var x = []
x === [] // false
x === x // true

const foo = {$: 'bar'}
Object.keys(foo) === ['$'] // false

if the goal is to check if the object is ['$'] the check should be arr.length === 1 && arr[0] === '$' but is this the goal?

All 6 comments

Hey @blacha thank-you for reaching out to us with your issue.

The warning generated actually doesn't make sense to me as XML can be an Object too and it can be empty.
With empty object it will return.

https://github.com/aws/aws-sdk-js/blob/master/lib/xml/node_parser.js#L142

I think it should be an issue for https://github.com/evanw/esbuild

Feel free to reach out if you think differently.

@ajredniwja I think this is a issue with the node_parser.js and not esbuild.

Since === compares the identity of objects, === [anything] will never equal true

Some examples

['$'] === ['$'] // false

var x = []
x === [] // false
x === x // true

const foo = {$: 'bar'}
Object.keys(foo) === ['$'] // false

if the goal is to check if the object is ['$'] the check should be arr.length === 1 && arr[0] === '$' but is this the goal?

This shouldn't have been closed. @blacha is 100% correct here #3430

Reopening as part of reviewing PR #3430

if the goal is to check if the object is ['$'] the check should be arr.length === 1 && arr[0] === '$' but is this the goal?

I'll go through some history to answer this question

The line in question is:
https://github.com/aws/aws-sdk-js/blob/b3b33bfb93e40024116251a76be1bda299b45448/lib/xml/node_parser.js#L142

The commit which added that line is https://github.com/aws/aws-sdk-js/commit/c794ac5c90072c5c231e17ec58b34201f82b9a66

From quick analysis, it appears that author wanted to check if array length is 1 and the key at index 0 is $ as explained by @blacha in their comment

Verified that esbuild is now able to bundle aws-sdk in v2.745.0 as follows:

$ yarn add aws-sdk esbuild

$ yarn list aws-sdk
yarn list v1.22.4
warning package.json: No license field
warning No license field
warning Filtering by arguments is deprecated. Please use the pattern option instead.
└─ [email protected]
✨  Done in 0.10s.

$ echo "require('aws-sdk')" > index.js

$ ./node_modules/.bin/esbuild --bundle index.js --platform=node --outdir=dist
Was this page helpful?
0 / 5 - 0 ratings