aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.11k stars 578 forks source link

Cannot transpile @aws-sdk/util-dynamodb #4643

Closed ajohnston1219 closed 1 year ago

ajohnston1219 commented 1 year ago

Checkboxes for prior research

Describe the bug

When trying to run tsc on a project with @aws-sdk/util-dynamodb, the build fails due to missing types from @aws-sdk/types. This is similar to #3437, but installing @aws/types explicitly does not fix the issue.

package.json

{
  "name": "@genie/constructs",
  "version": "0.1.0",
  "main": "lib/index.js",
  "types": "lib/index.d.ts",
  "scripts": {
    "build": "tsc",
    "watch": "tsc -w",
    "test": "jest"
  },
  "devDependencies": {
    "@types/jest": "^27.5.2",
    "@types/node": "10.17.27",
    "@types/prettier": "2.6.0",
    "aws-cdk-lib": "2.43.1",
    "constructs": "^10.0.0",
    "jest": "^27.5.1",
    "ts-jest": "^27.1.4",
    "@types/aws-lambda": "~8.10.114",
    "typescript": "~4.9.5"
  },
  "peerDependencies": {
    "aws-cdk-lib": "2.43.1",
    "constructs": "^10.0.0"
  },
  "dependencies": {
    "@aws-sdk/util-dynamodb": "~3.316.0",
    "@aws-sdk/types": "~3.310.0"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2018",
    "module": "commonjs",
    "lib": [
      "es2018",
      "dom"
    ],
    "declaration": true,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": false,
    "inlineSourceMap": true,
    "inlineSources": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "typeRoots": [
      "./node_modules/@types"
    ],
    "types": ["node", "jest"],
    "esModuleInterop": true
  },
  "exclude": [
    "node_modules",
    "cdk.out",
    "dist"
  ]
}

NOTE: This project was initialized using cdk init lib --language=typescript. Not much has been done other than trying to bring in the @aws-sdk/util-dynamodb dependency for unmarshalling.

SDK version number

@aws-sdk/util-dynamodb v3.316.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

tsc --version = Version 4.9.5

Reproduction Steps

Create project with cdk init lib --language=typescript

Install @aws-sdk/util-dynamodb

Make sure tsconfig.json matches above

Import unmarshall somewhere in the project

Run tsc in project directory

Observed Behavior

../../common/temp/node_modules/.pnpm/@aws-sdk+util-retry@3.257.0/node_modules/@aws-sdk/util-retry/dist-types/AdaptiveRetryStrategy.d.ts:1:20 - error TS2305: Module '"@aws-sdk/types"' has no exported member 'RetryErrorInfo'.

1 import { Provider, RetryErrorInfo, RetryStrategyV2, RetryToken, StandardRetryToken } from "@aws-sdk/types";
                     ~~~~~~~~~~~~~~

../../common/temp/node_modules/.pnpm/@aws-sdk+util-retry@3.257.0/node_modules/@aws-sdk/util-retry/dist-types/AdaptiveRetryStrategy.d.ts:1:36 - error TS2724: '"@aws-sdk/types"' has no exported member named 'RetryStrategyV2'. Did you mean 'RetryStrategy'?

1 import { Provider, RetryErrorInfo, RetryStrategyV2, RetryToken, StandardRetryToken } from "@aws-sdk/types";
                                     ~~~~~~~~~~~~~~~

../../common/temp/node_modules/.pnpm/@aws-sdk+util-retry@3.257.0/node_modules/@aws-sdk/util-retry/dist-types/AdaptiveRetryStrategy.d.ts:1:53 - error TS2305: Module '"@aws-sdk/types"' has no exported member 'RetryToken'.

1 import { Provider, RetryErrorInfo, RetryStrategyV2, RetryToken, StandardRetryToken } from "@aws-sdk/types";
                                                      ~~~~~~~~~~

../../common/temp/node_modules/.pnpm/@aws-sdk+util-retry@3.257.0/node_modules/@aws-sdk/util-retry/dist-types/AdaptiveRetryStrategy.d.ts:1:65 - error TS2305: Module '"@aws-sdk/types"' has no exported member 'StandardRetryToken'.

1 import { Provider, RetryErrorInfo, RetryStrategyV2, RetryToken, StandardRetryToken } from "@aws-sdk/types";
                                                                  ~~~~~~~~~~~~~~~~~~

../../common/temp/node_modules/.pnpm/@aws-sdk+util-retry@3.257.0/node_modules/@aws-sdk/util-retry/dist-types/StandardRetryStrategy.d.ts:1:20 - error TS2305: Module '"@aws-sdk/types"' has no exported member 'RetryErrorInfo'.

1 import { Provider, RetryErrorInfo, RetryStrategyV2, StandardRetryToken } from "@aws-sdk/types";
                     ~~~~~~~~~~~~~~

../../common/temp/node_modules/.pnpm/@aws-sdk+util-retry@3.257.0/node_modules/@aws-sdk/util-retry/dist-types/StandardRetryStrategy.d.ts:1:36 - error TS2724: '"@aws-sdk/types"' has no exported member named 'RetryStrategyV2'. Did you mean 'RetryStrategy'?

1 import { Provider, RetryErrorInfo, RetryStrategyV2, StandardRetryToken } from "@aws-sdk/types";
                                     ~~~~~~~~~~~~~~~

../../common/temp/node_modules/.pnpm/@aws-sdk+util-retry@3.257.0/node_modules/@aws-sdk/util-retry/dist-types/StandardRetryStrategy.d.ts:1:53 - error TS2305: Module '"@aws-sdk/types"' has no exported member 'StandardRetryToken'.

1 import { Provider, RetryErrorInfo, RetryStrategyV2, StandardRetryToken } from "@aws-sdk/types";
                                                      ~~~~~~~~~~~~~~~~~~

Found 7 errors in 2 files.

Errors  Files
     4  ../../common/temp/node_modules/.pnpm/@aws-sdk+util-retry@3.257.0/node_modules/@aws-sdk/util-retry/dist-types/AdaptiveRetryStrategy.d.ts:1
     3  ../../common/temp/node_modules/.pnpm/@aws-sdk+util-retry@3.257.0/node_modules/@aws-sdk/util-retry/dist-types/StandardRetryStrategy.d.ts:1

Expected Behavior

Successful transpilation

Possible Solution

This seems to be similar to #3437 except installing @aws-sdk/types explicitly does not fix it

Additional Information/Context

No response

ajohnston1219 commented 1 year ago

Okay, I believe I have found the issue. We are using @microsoft/rush for monorepo management, and somehow we ended up with side by side versions of @aws-sdk/types, one of which was version 3.0.0 exactly. Removing this, I had to resolve several peer dependency issues regarding things like @aws-sdk/client-dynamodb requires peer dependency @aws-sdk/types@^3.0.0. I am checking on our configuration now (I am new to rush), but my guess is that some setting in rush causes these dependencies to ignore the caret and install 3.0.0 exactly.

Regardless of the issue, if the minor versions of @aws-sdk/types include breaking changes, should these peer dependencies be updated to be more specific? Like specify a minimum working minor version so that package manager version resolution settings won't break a build? Also, there were multiple versions of @aws-sdk/types installed in our repo, and for whatever reason the import from @aws-sdk/types was automatically resolving to 3.0.0 instead of the higher versions. I'm guessing this is a rush issue.

This specific issue has been fixed for me by installing @aws-sdk/types explicitly in every service within the monorepo to make sure v3.0.0 doesn't exist anywhere. Therefore I will close the issue. But I think that a more specific version in the dependencies would be preferred if there are breaking changes in the minor versions. It seems like the version is defined with * (this is the case in @aws-sdk/client-dynamodb), which would imply that any version would work, but based on the issue I had as well as #3437 I believe this is incorrect now.

github-actions[bot] commented 1 year ago

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.