angular - Importing aws4 into an Angular2 app -


i trying use aws4 package sign requests in angular2 typescript2 app. have installed package , in node_modules.

in component.ts file, try import with:

import * aws4 'aws4'; 

when build project webpack, code complains cannot find module 'aws4'. however, in same directory if start node , run require('aws4') works, module there , has been installed.

@types/aws4 not available.

the interesting thing though typescript complains can't find aws4 seems still imported anyway. however, different error in browser: querystring.escape not function. think webpack build code such nodejs dependencies such querystring pollyfilled.

is there need add typescript code or webpack use aws4?

i can typing problem not shimming built-in node module problem:

the ts compiler doesn't know shape of aws4 module must supply it. say, module doesn't have typings available through npm means need create typings it. minimum need file named "aws4.d.ts" 1 line:

declare module "aws4"; 

import typing in "component.ts" /// <reference path="path/to/aws4.d.ts" />. if put typing in same directory "component.ts" can skip reference bit.

this minimal typing placates compiler though didn't tell ts true shape of library.

note: because ts compiler can't find dependency doesn't mean won't emit import statement code. that's why page still loads aws4 later fails on referencing querystring.escape.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -