Aws-sdk-js: error TS2318: Cannot find global type 'Symbol'.

Created on 19 Jul 2017  路  9Comments  路  Source: aws/aws-sdk-js

Hi,

I have node express app with Typescript. I installed aws-sdk and added following in tsconfig

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "outDir": "dist",
    "lib": [
            "es5",
            "es2015.promise"
        ]
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

In test.ts
import S3 = require('aws-sdk/clients/s3');---? compiler error in file [ can't find module aws-sdk/clients/s3 ]

compiler throw - error TS2318: Cannot find global type 'Symbol'.

package.json

 "@types/node": "^7.0.38",
  "typescript": "^2.4.1"

What I might be doing wrong?

Most helpful comment

I have removed the lib section and successfully able to perform S3.listBuckets.

All 9 comments

Do you see the error is you remove the line importing the S3 client? Since the compile target is set to es6 and the lib declaration only allows access to ES5 and promises, TypeScript's generated output may make references to Symbol that it is then unable to interpret.

No, but if I remove lib setting it does go away.

and after removing the setting

import S3 = require('aws-sdk/clients/s3');
 S3.listBuckets(params, function(err, data) {
     if (err) console.log(err, err.stack); // an error occurred
    else     console.log(data);    
    });

I am getting error TS2339: Property 'listBuckets' does not exist on type 'typeof S3'. error

@solankipriti
When calling operations on a client, you'll need to instantiate the client first.

S3 in your example is a constructor. If you set const s3 = new S3();, you should be able to call operations on the s3 object.

I have removed the lib section and successfully able to perform S3.listBuckets.

I copied the lib section from the referenced tsconfig.json here https://github.com/aws/aws-sdk-js/blob/master/ts/tsconfig.json as per the readme.md.

Adding that lib section broke my TS compilation. Removing it seems to work fine...

Does that example need updating?

Hi @adamdry, Do you mind sharing your current tsconfig?

Sure, with the issue it was:

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "outDir": "dist",
    "sourceMap": true,
    "lib": [
      "es5",
      "es2015.promise"
    ]
  },
  "files": [
    "./node_modules/@types/node/index.d.ts"
  ],
  "include": [
    "src/**/*.be.ts"
  ],
  "exclude": [
    "node_modules",
    "src/**/*.spec.ts"
  ]
}

Removing the lib section altogether fixed the issue and everything seems happy. You guys mentioned listBuckets which I'm not using so maybe that wouldn't work correctly... ?

For me adding "es5" to libs helped

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.

Was this page helpful?
0 / 5 - 0 ratings