aws / aws-sdk-js

AWS SDK for JavaScript in the browser and Node.js
https://aws.amazon.com/developer/language/javascript/
Apache License 2.0
7.57k stars 1.55k forks source link

AWS.SsoCredentials is not a constructor #4588

Closed atomicfraser closed 4 months ago

atomicfraser commented 4 months ago

Describe the bug

When I try to construct an instance of AWS.SsoCredentials I get the error:

new AWS.SsoCredentials({ profile: 'profile-name' })
^

TypeError: AWS.SsoCredentials is not a constructor
    at file:///Users/atomicfraser/src/playground-node/index.js:3:1
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Expected Behavior

I can construct an instance of AWS.SsoCredentials as per the documentation: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SsoCredentials.html

Current Behavior

When I try to construct an instance of AWS.SsoCredentials I get the error:

new AWS.SsoCredentials({ profile: 'profile-name' })
^

TypeError: AWS.SsoCredentials is not a constructor
    at file:///Users/atomicfraser/src/playground-node/index.js:3:1
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Reproduction Steps

  1. Create a plain node app as per the 'Getting Started' guide with aws-sdk installed
  2. Use the following code to create an instance of AWS.SsoCredentials:
    
    import * as AWS from 'aws-sdk'

new AWS.SsoCredentials({ profile: 'profile-name' })


3. Run the node app & observe the error

### Possible Solution

_No response_

### Additional Information/Context

The same error is thrown for multiple other classes such as `ProcessCredentials` and `SharedIniFileCredentials`

### SDK version used

2.1562.0, 2.1561.0, 2.1560.0, 2.1548.0

### Environment details (OS name and version, etc.)

Mac OS 14.1.1, Node 20.10.0
atomicfraser commented 4 months ago

This ended up being because we were using Cypress, which resolves the browser module, which doesn't contain the classes I was trying to use. To workaround this I used cy.task.