Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript error in an Angular 9 app with auth0-spa-js #365

Closed
Arnaud73 opened this issue Feb 28, 2020 · 7 comments
Closed

Typescript error in an Angular 9 app with auth0-spa-js #365

Arnaud73 opened this issue Feb 28, 2020 · 7 comments
Labels
beta This issue or PR relates to a beta release more info needed This issue is waiting for more information in order to progress

Comments

@Arnaud73
Copy link

Description

Using auth0-spa-js in an Angular 9 application results in a Typescript error during compilation.

Reproduction

When auth0-spa-js is used inside a new Angular 9 application, compilation fails with the following error:

ERROR in node_modules/@auth0/auth0-spa-js/dist/typings/index.d.ts:9:8 - error TS2440: Import declaration conflicts with local declaration of 'Auth0Client'.

9 import Auth0Client from './Auth0Client';
         ~~~~~~~~~~~

Imports are done this way:

import createAuth0Client from '@auth0/auth0-spa-js';
import Auth0Client from '@auth0/auth0-spa-js/dist/typings/Auth0Client';

Environment

Please provide the following:

  • Version of this library used: beta
  • Version of the platform or framework used, if applicable: Angular 9
  • Other relevant versions (language, server software, OS, browser): any
  • Other modules/plugins/libraries that might be involved:
@stevehobbsdev stevehobbsdev added the beta This issue or PR relates to a beta release label Feb 28, 2020
@stevehobbsdev
Copy link
Contributor

Thanks @Arnaud73. You should be able to do:

import createAuth0Client, { Auth0Client } from '@auth0/auth0-spa-js';

To import that type - does that cause the error to go away, or does it remain?

@stevehobbsdev stevehobbsdev added the more info needed This issue is waiting for more information in order to progress label Feb 28, 2020
@submarines-and
Copy link

submarines-and commented Feb 28, 2020

Same issue for us, syntax above does not work. Our workaround is to set "skipLibCheck": true, in tsconfig.json. We import:

import createAuth0Client, { Auth0Client, GetTokenSilentlyOptions, LogoutOptions, RedirectLoginOptions } from '@auth0/auth0-spa-js';

@Arnaud73
Copy link
Author

Thanks @stevehobbsdev!

Bad luck, it does not change a thing. Same error :(

For additionnal information, my AuthService is quite similar to the one defined in your documentation (https://auth0.com/docs/quickstart/spa/angular2/01-login). I guess yours, if implemented in a brand new Angular 9 project, will raise the error.

@Arnaud73
Copy link
Author

Thanks @submarines-and, your workaround is working for me. I'm going to stick with "skipLibCheck": true until the package is fixed

@stevehobbsdev
Copy link
Contributor

I'm not sure we're able to fix this particular issue any time soon. The way it has been built so far doesn't play very nicely with mixed default and named exports, so unfortunately we need to get a little bit hacky with the type system. To fix this though will mean a breaking change. This is absolutely something we want to fix in the future when we release a new major version though, and the interface around importing these types will change.

Thanks for the tip @submarines-and, if you don't mind I will add this to the FAQ for reference in the future.

@adamjmcgrath
Copy link
Contributor

This should be resolved by #367 - which is in the latest beta

Can you give v1.7.0-beta.4 a try?

@Arnaud73
Copy link
Author

Arnaud73 commented Mar 9, 2020

Seems to be working for me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta This issue or PR relates to a beta release more info needed This issue is waiting for more information in order to progress
Projects
None yet
Development

No branches or pull requests

4 participants