Rahul Bhooteshwar
Rahul Bhooteshwar

Reputation: 1955

Using jwt-decode with typescript front-end project

Description I am trying to use jwt-decode in a typescript project i.e. Stencil Project & it is throwing following error:

This expression is not callable.Type '{ default: (token: string, options?: Options) => TTokenDto; }' has no call signatures.

import * as jwt_decode from 'jwt-decode';
.
.
.
let token = "........";
let decoded = jwt_decode(token);

Reproduction

Upvotes: 18

Views: 14145

Answers (3)

Rahul Bhooteshwar
Rahul Bhooteshwar

Reputation: 1955

Following correction to the import statement works fine:

import jwt_decode from 'jwt-decode';

Update (November 2023): As pointed out in the comments, the package jwt-decode no loger has a default export. Therefore the correct import statement is now:

import { jwtDecode } from 'jwt-decode';

Upvotes: 51

Nico
Nico

Reputation: 316

For Angular 17 and newer you will need to import a named export instead (as @Jared Smith said)

import { jwtDecode } from 'jwt-decode';

Upvotes: 4

petereneric
petereneric

Reputation: 127

As said by Nico you have to import a named export instead, using Angular 17 and newer. However I had to use the slightly different line of code for making it run properly:

import {jwtDecode } from 'jwt-decode';

Upvotes: 1

Related Questions