Amplify-js: Could not find a declaration file for module '@aws-amplify/ui'

Created on 4 Jan 2019  路  12Comments  路  Source: aws-amplify/amplify-js

Describe the bug
When trying to build a typescript project I'm getting: Could not find a declaration file for module '@aws-amplify/ui':

node_modules/aws-amplify/lib/index.d.ts:8:16 - error TS7016: Could not find a declaration file for module '@aws-amplify/ui'. '/Users/samuelcastro/Projects/Control4/react-sdk/node_modules/@aws-amplify/ui/dist/aws-amplify-ui.js' implicitly has an 'any' type.
  Try `npm install @types/aws-amplify__ui` if it exists or add a new declaration (.d.ts) file containing `declare module '@aws-amplify/ui';`

8 import UI from '@aws-amplify/ui';

To Reproduce
Steps to reproduce the behavior:

  1. In a typescript (3.1.2) project run: ./node_modules/.bin/tsc
  2. See error

Expected behavior
Successfully build

Angular TypeScript UI feature-request

Most helpful comment

This should not be marked as a feature request, it completely breaks compiling

All 12 comments

Hey @samuelcastro, how are you including amplify into your project? I would like to reproduce this error and attempt to add type definitions to the amplify ui package.

At the moment Amplify UI does not have type definitions defined. It should be fairly easy to add them to provide Typescript support.

A workaround would be to add a new declaration as mentioned in the error or set noImplicitAny to false in your tsconfig.

I solved by adding a types.d.ts file in my src dir with:

declare module "@aws-amplify/ui"; // amplify hack :(

Yeah, an easy workaround would be just include it, I just wanted to see if a better solution is being take, like creating a typescript type definition of it.

Thanks anyway.

We have the same problem.

package.json:

    "aws-amplify": "1.1.18",

We import it like so (angular project)

import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { ICredentials } from '@aws-amplify/core';
import { CognitoUser } from 'amazon-cognito-identity-js';
import { Auth, AuthClass } from 'aws-amplify';
import { Observable } from 'rxjs/Observable';
import { fromPromise } from 'rxjs/observable/fromPromise';
import { map } from 'rxjs/operators';

It seems that in index.d.ts there is the following:

import Analytics, { AnalyticsClass, AnalyticsProvider, AWSPinpointProvider, AWSKinesisProvider } from '@aws-amplify/analytics';
import Auth, { AuthClass } from '@aws-amplify/auth';
import Storage, { StorageClass } from '@aws-amplify/storage';
import API, { APIClass, graphqlOperation } from '@aws-amplify/api';
import PubSub, { PubSubClass } from '@aws-amplify/pubsub';
import Cache from '@aws-amplify/cache';
import Interactions, { InteractionsClass } from '@aws-amplify/interactions';
import UI from '@aws-amplify/ui';
import XR, { XRClass } from '@aws-amplify/xr';
import Amplify, { ConsoleLogger as Logger, Hub, JS, ClientDevice, Signer, I18n, ServiceWorker } from '@aws-amplify/core';
export default Amplify;
export { Auth, Analytics, Storage, API, PubSub, I18n, Logger, Hub, Cache, JS, ClientDevice, Signer, ServiceWorker, Interactions, UI, XR };
export { AuthClass, AnalyticsClass, APIClass, StorageClass, PubSubClass, InteractionsClass, XRClass, AnalyticsProvider, AWSPinpointProvider, AWSKinesisProvider };
export { graphqlOperation };

import UI from '@aws-amplify/ui'; seems to be what results in the types being missing... although I'm not 100% on this :smile:

Of course its easy enough to get around with adding a file as above... but it would be nice with proper types...

Just stumbled upon this too. Everything else has a proper type declaration file in @aws-amplify. So this seems like just a tiny oversight. Other folders such as @aws-amplify/cache have a lib folder full of .d.ts files. But the UI folder does not.

This should not be marked as a feature request, it completely breaks compiling

Add "@aws-amplify/ui": "1.0.18", to package.json, below "aws-amplify": "1.1.26", and good luck :))

Any updates on this for Angular 8 support?

Still getting this error:

G:\Development\Personal\Wamplify>ng build --prod

chunk {0} runtime-es2015.703a23e48ad83c851e49.js (runtime) 1.41 kB [entry] [rendered]
chunk {1} main-es2015.efedd750490b14de3f18.js (main) 128 bytes [initial] [rendered]
chunk {2} polyfills-es2015.66a9e684cc8ebe117187.js (polyfills) 130 bytes [initial] [rendered]
chunk {3} styles.766cbe8e00b1dc50cc5e.css (styles) 62.6 kB [initial] [rendered]
Date: 2019-07-30T03:04:02.215Z - Hash: deb8ed06f76c4a940511 - Time: 13248ms

ERROR in node_modules/aws-amplify/lib/index.d.ts:8:8 - error TS1192: Module '"G:/Development/Personal/Wamplify/node_modules/@aws-amplify/ui/lib/index"' has no default export.

8 import UI from '@aws-amplify/ui';
         ~~

From package.json

    "aws-amplify": "^1.1.27",
    "@aws-amplify/ui": "^1.0.22",

IVY is NOT enabled.

I added
"noImplicitAny": false,
in my tsconfig.json and seems like the error is gone.

As the above callouts and merged PRs, this is resolved. Closing this issue

@sammartinez I still have this issue on the latest version. How do I solve it?

same problem

Was this page helpful?
0 / 5 - 0 ratings