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

Error Module has no exported member 'UserAgent' while using aws-sdk-js-v3 #1842

Closed
vishwasrao opened this issue Dec 24, 2020 · 30 comments · Fixed by aws/aws-sdk-js-crypto-helpers#188
Assignees
Labels
bug This issue is a bug.

Comments

@vishwasrao
Copy link

Describe the bug
I am using aws-sdk-js-v3 in my typescript project, I installed package with command yarn add @aws-sdk/client-s3.
After using S3Client in my typescript code

import { S3Client } from '@aws-sdk/client-s3';

Application starts failing with error

node_modules/@aws-sdk/client-s3/types/S3Client.d.ts:102:392 - error TS2305: Module '"../../types/dist/cjs"' has no exported member 'UserAgent'.
102 import { Provider, RegionInfoProvider, Credentials as __Credentials, Decoder as __Decoder, Encoder as __Encoder, EventStreamSerdeProvider as __EventStreamSerdeProvider, HashConstructor as __HashConstructor, HttpHandlerOptions as __HttpHandlerOptions, Logger as __Logger, Provider as __Provider, StreamCollector as __StreamCollector, StreamHasher as __StreamHasher, UrlParser as __UrlParser, UserAgent as __UserAgent } from "@aws-sdk/types";  
                                                                                   ~~~~~~~~~
node_modules/@aws-sdk/middleware-user-agent/dist/cjs/configurations.d.ts:1:20 - error TS2305: Module '"../../../types/dist/cjs"' has no exported member 'UserAgent'.

1 import { Provider, UserAgent } from "@aws-sdk/types";

SDK version number
3.1.0

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

Details of the Node.js version
$ node -v
v12.4.0

To Reproduce (observed behavior)

  1. Install package with command yarn add @aws-sdk/client-s3
  2. Import S3Client in typescript file import { S3Client } from '@aws-sdk/client-s3'; and use client to get object from S3.
  3. Start typescript application with command yarn run start:Dev
  4. It fails to start with given command

Note:
If I install package @aws-sdk/types with command yarn add @aws-sdk/types then this error goes away and works as expected.
Do we really need @aws-sdk/types package, Expectation was @aws-sdk/client-s3 will be sufficient.

Expected behavior
It should not give any error and extra package @aws-sdk/types should not be needed

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

@vishwasrao vishwasrao added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 24, 2020
@mfogel
Copy link

mfogel commented Dec 25, 2020

I am running into this error as well. I'm using v3.1.0 of the SDK.

I see it with a few other clients as well

  • ../../node_modules/@aws-sdk/client-dynamodb/types/DynamoDBClient.d.ts:58:304 - error TS2305: Module '"../../types/dist/cjs"' has no exported member 'UserAgent'.
  • ../../node_modules/@aws-sdk/client-api-gateway/types/APIGatewayClient.d.ts:128:304 - error TS2305: Module '"../../types/dist/cjs"' has no exported member 'UserAgent'.
  • ../../node_modules/@aws-sdk/client-s3/types/S3Client.d.ts:102:392 - error TS2305: Module '"../../types/dist/cjs"' has no exported member 'UserAgent'.

What appears to be going is that all three of these clients have a dependencies on

  • @aws-sdk/[email protected] and
  • @aws-crypto/sha256-browser@^1.0.0 - which in turn depends on @aws-sdk/types@^1.0.0-rc.1

I'm using yarn and when I grep through my node_modules, I don't see @aws-sdk/[email protected] only @aws-sdk/types@^1.0.0-rc.1. Hence when these clients are trying to import from @aws-sdk/types they're getting v1.0.0-rc1 when they are expecting to get v3.1.0

It looks like this was probably introduced in #1775

It looks like this would be fixed by aws/aws-sdk-js-crypto-helpers#187

Adding this to my package.json is working as a temporary work-around for me (again, using yarn)

"resolutions": {
  "@aws-sdk/types": "^3.1.0"
}

@kirintwn
Copy link

Using the the above temporary work-around resolutions in package.json is not working for me (using npm).

I have to explicitly install @aws-sdk/types as one of devDependencies, then the problems are gone:

npm install -D @aws-sdk/[email protected]

@jamesjrg
Copy link

jamesjrg commented Dec 29, 2020

Installing @aws-sdk/types as above made this error go away, but then I got another error:

node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:42 - error TS1005: ',' expected.

92 export declare type UserAgentPair = [name: string, version?: string];
                                            ~
node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:60 - error TS1005: ',' expected.

92 export declare type UserAgentPair = [name: string, version?: string];

I guess that package doesn't work with strict mode enabled.

@prime417
Copy link

Installing @aws-sdk/types as above made this error go away, but then I got another error:

node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:42 - error TS1005: ',' expected.

92 export declare type UserAgentPair = [name: string, version?: string];
                                            ~
node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:60 - error TS1005: ',' expected.

92 export declare type UserAgentPair = [name: string, version?: string];

I guess that package doesn't work with strict mode enabled.

I am also getting same issue.Looking for any solution.

@olokobayusuf
Copy link

Hey everyone, I just wanted to let you know that the following seems to fix this issue:

  1. As @kirintwn mentioned, install the types package:
    npm install -D @aws-sdk/[email protected]
    
  2. Then upgrade Typescript, I'm on 4.1.3:
    npm install typescript@latest
    

I hope this is useful.

@peterlogo
Copy link

@olokobayusuf thanks your solution worked for me.

@sozakir
Copy link

sozakir commented Jan 4, 2021

I am also getting the same error as @prime417 after explicitly installing types.

As I am using angular 9.1.12 which uses typescript version 3.8.3, as soon as I switched to 4.1.3, I am getting this error. In order to have this hack work for me I need to upgrade the angular version to 10.1.0 or above.

Compiling TypeScript sources through ngc
ERROR: The Angular Compiler requires TypeScript >=3.6.4 and <3.9.0 but 4.1.3 was found instead.
An unhandled exception occurred: The Angular Compiler requires TypeScript >=3.6.4 and <3.9.0 but 4.1.3 was found instead.

waiting for it to be resolved and any other suggestions?

@BCarroll524
Copy link

@olokobayusuf your solution has also worked for me. Thank you

@AllanZhengYP
Copy link
Contributor

Thanks everyone for the thorough investigation. @olokobayusuf 's solution should solve the problem. Although the @aws-sdk/[email protected] should have pinned dependency over @aws-sdk/[email protected]. We need to dive deeper into this on our end.

@AllanZhengYP AllanZhengYP added needs-triage This issue or PR still needs to be triaged. and removed needs-triage This issue or PR still needs to be triaged. labels Jan 5, 2021
@olokobayusuf
Copy link

Thanks everyone for the thorough investigation. @olokobayusuf 's solution should solve the problem. Although the @aws-sdk/[email protected] should have pinned dependency over @aws-sdk/[email protected]. We need to dive deeper into this on our end.

Hey there @AllanZhengYP I hate to discuss a different issue, but my development is completely blocked on #1857 . I don't mind making a custom fork of the SDK with a fix while you all work on an official update, but I need a fix ASAP.

@alexforsyth alexforsyth self-assigned this Jan 5, 2021
@p-obrien
Copy link

p-obrien commented Jan 6, 2021

This isn't working for me with the EC2 Client, after applying @olokobayusuf solution I'm getting the following:

node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:42` - error TS1005: ',' expected.
92 export declare type UserAgentPair = [name: string, version?: string];
                                            
node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:60 - error TS1005: ',' expected.
92 export declare type UserAgentPair = [name: string, version?: string];

Thanks everyone for the thorough investigation. @olokobayusuf 's solution should solve the problem. Although the @aws-sdk/[email protected] should have pinned dependency over @aws-sdk/[email protected]. We need to dive deeper into this on our end.

@trivikr
Copy link
Member

trivikr commented Jan 6, 2021

I don't mind making a custom fork of the SDK with a fix while you all work on an official update, but I need a fix ASAP.

@olokobayusuf You can also post a PR with a fix on this repo.

@olokobayusuf
Copy link

This isn't working for me with the EC2 Client, after applying @olokobayusuf solution I'm getting the following:

node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:42` - error TS1005: ',' expected.
92 export declare type UserAgentPair = [name: string, version?: string];
                                            
node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:60 - error TS1005: ',' expected.
92 export declare type UserAgentPair = [name: string, version?: string];

Thanks everyone for the thorough investigation. @olokobayusuf 's solution should solve the problem. Although the @aws-sdk/[email protected] should have pinned dependency over @aws-sdk/[email protected]. We need to dive deeper into this on our end.

Check your Typescript version. You're likely getting this error because you're running on TS 3.x.

@olokobayusuf
Copy link

I don't mind making a custom fork of the SDK with a fix while you all work on an official update, but I need a fix ASAP.

@olokobayusuf You can also post a PR with a fix on this repo.

That's fine by me, I just need to know how to fix it. I haven't done too much static analysis on the codebase because I haven't had the time. I'm unfamiliar with the middleware stack, but I'm guessing any fix would be either working around the middleware stack, or making the keys within the stack unique so that the conflict never pops up (this would be harder because there isn't a global state for knowing how many requests are in flight AFAIK, so I'd have to resort to something hacky like appending a UUID to the key for each entry). I just need a quick rundown and I'll try to hash it out as quickly as possible.

@trivikr
Copy link
Member

trivikr commented Jan 6, 2021

This issue is happening as @aws-sdk/types is declared as a dependency instead of devDependency in the following packages:

  • @aws-crypto/sha256-browser
  • @aws-crypto/sha256-js
  • @aws-sdk/util-user-agent-browser
  • @aws-sdk/util-user-agent-node
$ yarn why @aws-sdk/types
yarn why v1.22.10
warning package.json: No license field
[1/4] 🤔  Why do we have the module "@aws-sdk/types"...?
[2/4] 🚚  Initialising dependency graph...
warning No license field
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "@aws-sdk/[email protected]"
info Has been hoisted to "@aws-sdk/types"
info Reasons this module exists
   - Hoisted from "@aws-sdk#client-s3#@aws-crypto#sha256-browser#@aws-sdk#types"
   - Hoisted from "@aws-sdk#client-s3#@aws-crypto#sha256-js#@aws-sdk#types"
info Disk size without dependencies: "524KB"
info Disk size with unique dependencies: "524KB"
info Disk size with transitive dependencies: "524KB"
info Number of shared dependencies: 0
=> Found "@aws-sdk/util-user-agent-browser#@aws-sdk/[email protected]"
info This module exists because "@aws-sdk#client-s3#@aws-sdk#util-user-agent-browser" depends on it.
info Disk size without dependencies: "540KB"
info Disk size with unique dependencies: "540KB"
info Disk size with transitive dependencies: "540KB"
info Number of shared dependencies: 0
=> Found "@aws-sdk/util-user-agent-node#@aws-sdk/[email protected]"
info This module exists because "@aws-sdk#client-s3#@aws-sdk#util-user-agent-node" depends on it.
info Disk size without dependencies: "540KB"
info Disk size with unique dependencies: "540KB"
info Disk size with transitive dependencies: "540KB"
info Number of shared dependencies: 0
✨  Done in 0.16s.

ToDo: Move @aws-sdk/types to devDependency in the affected packages.

@trivikr
Copy link
Member

trivikr commented Jan 6, 2021

@ykoglin
Copy link

ykoglin commented Jan 8, 2021

This isn't working for me with the EC2 Client, after applying @olokobayusuf solution I'm getting the following:

node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:42` - error TS1005: ',' expected.
92 export declare type UserAgentPair = [name: string, version?: string];
                                            
node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:60 - error TS1005: ',' expected.
92 export declare type UserAgentPair = [name: string, version?: string];

Thanks everyone for the thorough investigation. @olokobayusuf 's solution should solve the problem. Although the @aws-sdk/[email protected] should have pinned dependency over @aws-sdk/[email protected]. We need to dive deeper into this on our end.

Check your Typescript version. You're likely getting this error because you're running on TS 3.x.
tsc -v
Version 4.1.3
"dependencies":
"@aws-sdk/client-dynamodb": "^3.1.0",
"@aws-sdk/client-s3": "^3.1.0",
"@aws-sdk/util-dynamodb": "^3.1.0",
"devDependencies":
"@aws-sdk/types": "^3.1.0",

node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:42 - error TS1005: ',' expected.

92 export declare type UserAgentPair = [name: string, version?: string];
~

node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:60 - error TS1005: ',' expected.

92 export declare type UserAgentPair = [name: string, version?: string];

@mfogel
Copy link

mfogel commented Jan 9, 2021

Still seeing this bug with yesterday's release of the SDK, v3.2.0, on both typescript 4.0 & 4.1.

Since a couple PR's were merged in over in https://github.com/aws/aws-sdk-js-crypto-helpers, I think this is now just blocked on a new release of the various packages from that repo.

/cc @seebees

@trivikr
Copy link
Member

trivikr commented Jan 9, 2021

Since a couple PR's were merged in over in https://github.com/aws/aws-sdk-js-crypto-helpers, I think this is now just blocked on a new release of the various packages from that repo.

The next version of crypto-helpers is expected to release on Wed 1/13. We'll release JS SDK v3 v3.3.0 consuming new crypto-helpers version by Thu 1/14

@alexforsyth
Copy link
Contributor

Posting this here for documentation and visibility.

TLDR:
We're moving @aws-sdk/types to dependencies so that you get types right out of the box at the cost of an increase of 492kb in package size. This will not impact users that use bundlers.


After some investigation we've come to the conclusion that @aws-sdk/types should be exposed as a "dependency" in all packages where a non-test file depends on types. I'll be making updates to @aws-crypto/* and @aws-sdk/* shortly. I've published my own versions to my local npm registry to confirm that these updates should fix this family of issues moving forward.

Background
Customers consume @aws-sdk/* with types but we declare @aws-sdk/types as a devDependency in all packages in this repo. @trivikr showed in #1842 (comment) that right now customers are getting access to @aws-sdk/types somewhat erroneously through a version of @aws-crypto/sha256-{js, browser} which brings in the most recent rc version of @aws-sdk/types as a dependency, since this is the only place where @aws-sdk/types are declared as a dependency, this is what consumers of @aws-sdk are actually using for @aws-sdk/types under the hood and why it hadn't broken until types were updated with useragent in 3.1.0.

Like @olokobayusuf mentioned including @aws-sdk/types as a dependency yourself will also fix the issue.

Why are we doing this?
When a package is declared as a devDependency it is (rightfully) not propagated to downstream consumers of that package. We publish packages that are consumed by downstream users, they should have access to types right out of the box without the need to install @aws-sdk/types themselves. Since we want our consumers to automatically get our type declarations we must declare these types as dependencies. See: microsoft/types-publisher#81 (comment)

Wont this increase node module size?
Yes, it will increase node module size by ~492kb. This is an issue brought up #1649.
However, @DanielRosenwasser brings up a good point in microsoft/types-publisher#81 (comment) that

breaking consumers is a worse problem than slightly-larger packages, we've made --save the default in our documentation.

The AWS SDK team (and I personally) agree. Additionally most JS users use bundlers anyway that should strip out these files.

@alexforsyth
Copy link
Contributor

This should be going out with our next release. Huge shout out to @olokobayusuf!

@MarrickLip
Copy link

@alexforsyth glad to see this fixed!

Is it worth reviewing how this got through testing? This feels to me like the sort of thing that would be caught in CICD etc. before ever shipping.

@alexforsyth
Copy link
Contributor

@MarrickLip We're working on it, I dont have anything I can post to the public quite yet

@markusl
Copy link

markusl commented Jan 13, 2021

@alexforsyth just to confirm, the new release is also supposed to fix the already reported issue about this

node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:42` - error TS1005: ',' expected.
92 export declare type UserAgentPair = [name: string, version?: string];

Just checking if it needs another issue to be fixed. I'm currently hitting this when using explicit dependency to @aws-sdk/types.

@alexforsyth alexforsyth removed the needs-triage This issue or PR still needs to be triaged. label Jan 13, 2021
@alexforsyth
Copy link
Contributor

alexforsyth commented Jan 13, 2021

@markusl yes it should be fixed. If you run yarn why @aws-sdk/types or npm ls @aws-sdk/types in your repo currently it should show something like this:

yarn why @aws-sdk/types
yarn why v1.22.5
[1/4] 🤔  Why do we have the module "@aws-sdk/types"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "@aws-sdk/[email protected]"
info Reasons this module exists
   - "@aws-crypto#sha256-js" depends on it
   - Hoisted from "@aws-crypto#sha256-js#@aws-sdk#types"
   - Hoisted from "@aws-sdk#client-dynamodb#@aws-crypto#sha256-browser#@aws-sdk#types"
info Disk size without dependencies: "528KB"
info Disk size with unique dependencies: "528KB"
info Disk size with transitive dependencies: "528KB"
info Number of shared dependencies: 0

In the next version there will be no dependencies on "@aws-sdk/[email protected]" so you should be getting the correct types. I believe you can still mitigate this issue with the current release by taking a dependency on @aws-sdk/types@^3.1.0 yourself. I actually just ran this myself to confirm. If you're still encountering an issue after you've taken the @aws-sdk/types dependency yourself, can you post the results of your yarn why?

@mfogel
Copy link

mfogel commented Jan 15, 2021

As of yesterday's v3.3.0 release, this issue appears to be fixed. No more need for the workarounds. Thanks for getting that release out last night AWS team.

@adaadamczak007
Copy link

adaadamczak007 commented Jan 15, 2021

Hi, still having issues...
is v3.3.0 supposed to work with typescript 3.7.x?

I still see after upgrade to v3.3.0:

node_modules/@aws-sdk/types/dist/cjs/util.d.ts:92:60 - error TS1005: ',' expected.

92 export declare type UserAgentPair = [name: string, version?: string];

@alexforsyth
Copy link
Contributor

alexforsyth commented Jan 15, 2021

@adaadamczak007 please upgrade to typescript ^4.0.0. This issue is slightly different and tracked here: #1919.

TS doesn’t have LTS concept, they drop support for previous version when the new one is released. I'll post updates when I can make more public, we're working on guidance around this internally!

@alexforsyth
Copy link
Contributor

Closing this bug as 3.3.x should solve this family of issues! Thanks for your support all!

@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 Jan 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.