Auth0-spa-js: TypeScript problem with 1.4.0.

Created on 30 Oct 2019  路  14Comments  路  Source: auth0/auth0-spa-js

Description

After upgrading from 1.3.2 to 1.4.0, my app fails to build with TypeScript. I'm using the React SPA Quick Start code, ported to TypeScript. I don't think port to TypeScript matters so much, but I mention it because it means my quick start file is being passed through the TypeScript compiler. The TypeScript failure comes for an import statement that also appears in the original quick start code:

TypeScript error in /home/nirvdrum/dev/workspaces/cloudtruth/ctweb/src/reactAuth0Spa.tsx(2,31):
Could not find a declaration file for module '@auth0/auth0-spa-js'. '/home/myuser/dev/workspaces/myproject/node_modules/@auth0/auth0-spa-js/dist/lib/auth0-spa-js.cjs.js' implicitly has an 'any' type.
  Try `npm install @types/auth0__auth0-spa-js` if it exists or add a new declaration (.d.ts) file containing `declare module '@auth0/auth0-spa-js';`  TS7016

    1 | import React, { useState, useEffect, useContext } from 'react'
  > 2 | import createAuth0Client from '@auth0/auth0-spa-js'
      |                               ^
    3 | import Auth0Client from '@auth0/auth0-spa-js/dist/typings/Auth0Client'
    4 | 
    5 | interface Auth0Context {

If roll back to @auth/auth0-spa-js 1.3.2, the problem goes away.

Reproduction

Pass the Auth0 React SPA Quick Start code through the TypeScript compiler or use the TypeScript port of the Quick Start code.

Environment

@auth0/auth0-spa-js: 1.4.0
typescript: 3.6.4

Most helpful comment

I spent some more time looking into this. The issue is pretty straightforward. The type definitions used to be in dist/typings and now there's an extra directory in between, making it dist/typings/src. However, this library's package.json still points to the old index.d.ts location. That part needs to be fixed in the library. With that change in place I encounter another error, but that's due to the import statement taken from the TypeScript port of the Quick Start code now pointing at an invalid location.

I can work up a PR for the immediate problem, but should this change even have been made? It looks like putting type definitions directly in typings/ is the common practice.

All 14 comments

It looks like merging #234 might fix the problem, or at least is a step in the right direction.

@nirvdrum Ah good, I came in to ask if #234 would solve your issue. We're just waiting on the author to fix some things up.

I haven't verified that branch, FYI. Just looking at it, it looks like it could be helpful. I'll have to clone, rebase, and use the package locally. In the meanwhile, I'll stick with 1.3.2.

I spent some more time looking into this. The issue is pretty straightforward. The type definitions used to be in dist/typings and now there's an extra directory in between, making it dist/typings/src. However, this library's package.json still points to the old index.d.ts location. That part needs to be fixed in the library. With that change in place I encounter another error, but that's due to the import statement taken from the TypeScript port of the Quick Start code now pointing at an invalid location.

I can work up a PR for the immediate problem, but should this change even have been made? It looks like putting type definitions directly in typings/ is the common practice.

@nirvdrum Looking at it, I agree. You're right in that it should be dist/typings/src. It used to be set to that and previously we thought it had regressed.

It looks like putting type definitions directly in typings/ is the common practice.

We do actually specify that directory but the Rollup plugin that generates the typings must also be picking up the src directory somehow. Let me look into that further.

This is an issue with angular and can easily be reproduced by downloading your own sample code https://github.com/auth0-samples/auth0-angular-samples/tree/master/01-Login and updating the package to 1.4.0

@nirvdrum 1.4.1 has now been released, if you'd like to give that a try and see if it fixes your issue.

@nirvdrum @ttrevorr We've had to backtrack on this slightly, as we realised it would break existing apps that reference the types directly by path. Instead of amending the path to the typings in package.json, we simply moved the files back where they were. We released this in 1.4.2, so you should upgrade to that to get the latest behaviour.

@stevehobbsdev Confirmed working. Thanks for the quick turnaround.

I don't understand why types such as Auth0Client aren't just exported from the index.d.ts file in the first place.

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

just gives me:

Module not found: Can't resolve '@auth0/auth0-spa-js/dist/typings/Auth0Client' in '/Users/ggp/dev/git/acnw2/packages/ui/src/components/Acnw/Auth'

from my CRA app.

ah, just found https://github.com/auth0/auth0-spa-js/pull/310, looks like there's a likely fix on it's way. Sweet.

@ggascoigne Yes we have a fix being rolled into the 1.7 beta, I'm just waiting on a couple more PRs going through review before release. Hopefully not long.

Any update?
I'm still having this issue on version 1.6.4 and typescript 3.8.3

@l222p Yes the fix is deployed into the beta if you'd like to try it. There should be no breaking changes there so you should be able to start using it without any changes.

@auth0/auth0-spa-js@beta

Would love to hear some feedback on the TypeScript typings if you get a change to try it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

patrickcorrigan picture patrickcorrigan  路  3Comments

alexislucas-toast picture alexislucas-toast  路  3Comments

Arnaud73 picture Arnaud73  路  7Comments

jgbpercy picture jgbpercy  路  7Comments

stupidSheep picture stupidSheep  路  4Comments