user3547774
user3547774

Reputation: 1689

Typescript Auth0 module

I have the following .d.ts file (extract of it)

declare const Auth0: Auth0Static;

declare module "auth0-js" {
    export = Auth0
}

Now in my .ts file I am using the following

import { Auth0 } from 'auth0-js';

I get the following error

auth0-js has no exported member Auth0

Whats going wrong here?

Upvotes: 1

Views: 1395

Answers (3)

Sumit Dhameja
Sumit Dhameja

Reputation: 141

You can include auth0 script in index.html

and inside your auth.ts. You can use

declare var auth0: any;

That avoids any name not found errors that typescript might raise.

Upvotes: 0

Vojtech
Vojtech

Reputation: 2816

In our angular-cli project we successfully set it up by

npm install auth0-js @types/auth0-js --save

and importing paths that you need like import { WebAuth } from 'auth0-js';

Upvotes: 3

jgranstrom
jgranstrom

Reputation: 586

The auth0-js library does not export anything named Auth0.

If you just want to import everything then change your import to import * as Auth0 from 'auth0-js'. Otherwise your can import the individual exports like import { WebAuth } from 'auth0-js';

Also, are you making your own typings? Otherwise you can just use the already available typings from npm install @types/auth0-js.

Make sure your tsconfig.json is configured to lookup the typings:

{
  "compilerOptions": {
    ...
    "typeRoots": [
      "node_modules/@types"
    ],
    ...
  }
}

Upvotes: 3

Related Questions