Module has no exported member 'AWS'
Asked Answered
W

4

6

Can someone help me understand how different the namespace and module is?

AWS.d.ts

declare module AWS {
  ...
  ...
}
export = AWS

helper.d.ts

export declare namespace Helpers{
  ...
  ...
}

app.component.d.ts

import {Helpers} from 'mystartup_commons'; //<= works fine
import {AWS} from 'aws-sdk';

Error:

ERROR in /Users/ishandutta2007/Documents/Projects/myproj/src/app/app.component.ts (1,9): Module '"/Users/is handutta2007/Documents/Projects/myproj/node_modules/aws-sdk/typings/AWS"' has no exported member 'AWS'.)

Wingless answered 25/3, 2017 at 19:22 Comment(0)
W
14

adding a reference path to node's definition file and using * as did the trick

app.component.d.ts

/// <reference path="../../node_modules/@types/node/index.d.ts"/>
import * as AWS from 'aws-sdk';
Wingless answered 26/3, 2017 at 1:2 Comment(1)
The downside to this is that it might import all of the AWS library and defeat tree shaking.Joule
Y
5

I believe that the reason that the aws-sdk has no default export is because they want developers to only import the packages they need. e.g.

import { s3 } from 'aws-sdk';

Yodel answered 24/8, 2018 at 12:51 Comment(0)
G
0
  1. You have a typo: modeule instead of module
  2. Seems like you can't export whole module. See here https://www.typescriptlang.org/docs/handbook/modules.html https://www.typescriptlang.org/docs/handbook/namespaces-and-modules.html
Gerita answered 25/3, 2017 at 19:31 Comment(0)
E
-1

Issue was resolve on Github: node_modules/aws-sdk/index has no default export #2654

Import module you want to use instead of AWS from aws-sdk

Javascript sample:

const aws = require('aws-sdk')
let s3 = new aws.S3();

Typescript:

import { config, S3 } from 'aws-sdk';
import {
  Buckets,
  GetObjectOutput,
  ListBucketsOutput,
  PutObjectRequest 
} from 'aws-sdk/clients/s3';
import { createReadStream } from 'fs';
Equation answered 10/2, 2021 at 0:32 Comment(1)
Some elaboration would be really appreciated.Dunstable

© 2022 - 2024 — McMap. All rights reserved.