aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

Unable to use S3 with TypeScript and Yarn 3, missing dependencies

Open vhiairrassary opened this issue 3 years ago • 4 comments

Describe the bug

We are unable to use AWS S3 SDK with TypeScript and Yarn 3 as some types dependencies (from @aws-sdk/node-config-provider) are missing in several packages: @aws-sdk/config-resolver, @aws-sdk/middleware-bucket-endpoint and @aws-sdk/middleware-retry.

Steps to reproduce

Minimal repository https://github.com/vhiairrassary/aws-sdk-js-v3-bug-report

Running yarn then yarn run build will produce the following errors (truncated):

.yarn/cache/@aws-sdk-config-resolver-npm-3.40.0-70d76c189b-0f8a153e1c.zip/node_modules/@aws-sdk/config-resolver/dist-types/endpointsConfig/NodeUseDualstackEndpointConfigOptions.d.ts:1:39 - error TS2307: Cannot find module '@aws-sdk/node-config-provider' or its corresponding type declarations.

1 import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider";
                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.yarn/cache/@aws-sdk-config-resolver-npm-3.40.0-70d76c189b-0f8a153e1c.zip/node_modules/@aws-sdk/config-resolver/dist-types/endpointsConfig/NodeUseFipsEndpointConfigOptions.d.ts:1:39 - error TS2307: Cannot find module '@aws-sdk/node-config-provider' or its corresponding type declarations.

1 import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider";

I think the issue is due to missing types dependencies. Yarn 3, when used using PnP operating under strict mode (the default) requires dependencies to be correctly declared for every package. To fix the issue, apply the following patch (to the minimal repository, to ask Yarn 3 to override dependencies until fixed upstream) to add missing dependencies:

diff --git a/.yarnrc.yml b/.yarnrc.yml
index 9e303c3..29a8ca1 100644
--- a/.yarnrc.yml
+++ b/.yarnrc.yml
@@ -1 +1,12 @@
 yarnPath: .yarn/releases/yarn-3.1.1.cjs
+
+packageExtensions:
+  "@aws-sdk/config-resolver@*":
+    peerDependencies:
+      "@aws-sdk/node-config-provider": "*"
+  "@aws-sdk/middleware-bucket-endpoint@*":
+    peerDependencies:
+      "@aws-sdk/node-config-provider": "*"
+  "@aws-sdk/middleware-retry@*":
+    peerDependencies:
+      "@aws-sdk/node-config-provider": "*"

Running yarn then yarn run build now works as expected.

vhiairrassary avatar Dec 23 '21 08:12 vhiairrassary

Tried doing that and looks like I've partially solved, now I'm getting:

Cannot find module '@aws-sdk/types' or its corresponding type declarations.

1 import { ParsedIniData } from "@aws-sdk/types";
                                ~~~~~~~~~~~~~~~~

Negan1911 avatar Apr 26 '22 05:04 Negan1911

I have the same issue, is there any update on providing yarn 3 support?

chav-aniket avatar Jun 19 '22 15:06 chav-aniket

This could have been fixed by https://github.com/aws/aws-sdk-js-v3/pull/2928. That PR is now out of date, but the issue is a simple package dependency mistake that is exposed when using yarn or pnpm.

barryhagan avatar Jun 29 '22 14:06 barryhagan

Confirmed this issue. Will assign to the development team and added a p1 tag because I see it impacts multiple users.

Thanks.

RanVaknin avatar Aug 03 '22 20:08 RanVaknin

Just bumping this here. We ran into this issue too because the @aws-sdk/types package and the ones above were listed as devDependencies instead of dependencies.

This doesn't work because it's being reexported and is therefore a peer or actual dependency when trying to examine the package for self-consistency.

hanseltime avatar Mar 20 '23 21:03 hanseltime

We have moved all types imports to dependencies and not devDeps.

kuhe avatar Feb 23 '24 19:02 kuhe

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[bot] avatar Mar 09 '24 00:03 github-actions[bot]