5

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'.)

ishandutta2007
  • 16,676
  • 16
  • 93
  • 129

4 Answers4

11

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';
ishandutta2007
  • 16,676
  • 16
  • 93
  • 129
4

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';

edzillion
  • 3,592
  • 5
  • 31
  • 50
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
Sergey Mell
  • 7,780
  • 1
  • 26
  • 50
-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';