Aws-xray-sdk-node: After installing sdk version 3.3.0 Typescript compilation error

Created on 12 Apr 2021  路  11Comments  路  Source: aws/aws-xray-sdk-node

../node_modules/aws-xray-sdk-core/lib/patchers/aws3_p.ts:7:40 - error TS2307: Cannot find module '@aws-sdk/config-resolver' or its corresponding type declarations.

7 import type { RegionInputConfig } from '@aws-sdk/config-resolver';
~~~~~~

../node_modules/aws-xray-sdk-core/lib/patchers/aws3_p.ts:85:43 - error TS2339: Property 'serviceId' does not exist on type 'Configuration'.

85 const serviceIdentifier = client.config.serviceId;
~~~~~

Found 2 errors.

The typescript compiler is giving the above errors on build.

bug

Most helpful comment

@juancri thanks a ton for investigating & weighing in on this. We'll have a discussion on the team to see whether to do a separate module or bundle them in the main package. I'll also discuss about having a minimum supported TS version based on those 3.x errors.

All 11 comments

I have the same error now compiling a project in typescript

Apologies for the issue! We're taking a look.

Hey everyone,

Does anyone have a clean reproduction case? Or, additional stack traces would be beneficial.

@organic-scholar @Dema1348 I'm attempting to reproduce this issue with a TypeScript sample app but am having no luck. I'm using v3.7.3 of tsc, v9.1.1 of ts-node to run my sample TypeScript app. My tsconfig.json is:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "strict": true,
    "strictNullChecks": true,
    "declaration": true,
    "esModuleInterop": true
  },
  "files": ["index.ts"]
}

Can you provide the details of your setup requested by @awssandra so we can try to reproduce this locally?

@organic-scholar @Dema1348 I've released v3.3.1 which rolls back the AWS SDK V3 support and should resolve your compiler issues for now while we work to resolve the underlying issue. Please let me know if upgrading to 3.3.1 fixes this problem.

Thanks, @willarmiros v3.3.1 compiled successfully,

my project has the following ts version and config

typescript: ~3.9.7

{
  "compilerOptions": {
    "target": "ES2018",
    "module": "CommonJS",
    "lib": ["es2018"],
    "declaration": false,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noImplicitReturns": true,
    "incremental": true,
    "noFallthroughCasesInSwitch": false,
    "inlineSourceMap": true,
    "esModuleInterop": true,
    "inlineSources": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "strictPropertyInitialization": false,
    "outDir": "build",
  },
  "include": ["src", "typings"]
}

Thank @willarmiros , my project now works
typescript 3.7.4

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "lib": ["ES2020.Promise"],
    "skipLibCheck": true,
    "allowJs": true
  }
}

Thanks both for your info! I was able to reproduce the initial error posted by @organic-scholar. Interestingly, it didn't seem to have anything to do with the contents of my tsconfig, but instead depended on the version of TypeScript I was compiling with. When I compile with TypeScript 4.x, I get the errors that you've described. When compiling with TS 3.7.4 and 3.9.7, keeping everything else the same, I just get these errors:

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

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

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

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


Found 2 errors.

Which are documented in https://github.com/aws/aws-sdk-js-v3/issues/1842 and fixed for TypeScript 4.x users. So that leaves me with 2 questions:

  1. @organic-scholar @Dema1348 you both said you're using TS 3.x, but I can only reproduce your error with TS 4.x. Are you sure that you're compiling with 3.x? Not sure if there is some confusion with e.g. the version of your TypeScript dev dependency vs. the tsc --version on your local machine.
  2. Regardless, I think the way to resolve this is to add a runtime dependency, not dev dependency, on the X-Ray SDK for the following packages:
    a. @aws-sdk/smithy-client
    b. @aws-sdk/types
    c. @aws-sdk/config-resolver
    d. @aws-sdk/node-config-provider

Currently, we only have a dev dependency on those packages because we only used them for their Types. This is fine for JavaScript consumers of the SDK because they only consume the compiled aws3_p.js file, which no longer has any dependency on these packages. But we did not account for TypeScript consumers who would pull in the original aws3_p.ts file which does have references to these modules. Including these as runtime dependencies adds a small amount of bloat (just 1 kilobyte or so per package, according to Bundlephobia) in return for reliable builds for all customers, which seems like the right tradeoff to me.

The change introduces a runtime dependency for AWS SDK v3. The team should decide what's the best route there. Introducing a runtime dependency for AWS SDK v3 could have some costs in terms of bundle size or node_modules size for users who are either not using any AWS SDK or using AWS SDK v2 (and also, are not tree-shaking their output).

Another way to accomplish this could be to move the AWS SDK v3 support to another package which can depend on both this X-Ray SDK and the AWS SDK v3 (Proof of concept needed)

About TypeScript 3, it looks like compilation fails because of the lack of support for tuples.

@juancri thanks a ton for investigating & weighing in on this. We'll have a discussion on the team to see whether to do a separate module or bundle them in the main package. I'll also discuss about having a minimum supported TS version based on those 3.x errors.

Fixed as of v3.3.3.

Was this page helpful?
0 / 5 - 0 ratings