can't import jsonwebtoken in modern typescript esm app
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- node.js, typescript
- Ambito
- authentication, backend, security
Direzione di ricerca
Non vengono indicati file o test. Inizia dagli esempi di importazione e dalla issue correlata #655, quindi esamina le esportazioni dei moduli attuali del package e la configurazione delle dichiarazioni. Il lavoro è completato quando un’app ESM moderna in TypeScript può importare sign, verify e i relativi tipi delle opzioni senza uno shim, e il comportamento a runtime e i typings concordano.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
we can't properly import this library in a modern typescript project. here's the problem:
import * as jwt from "jsonwebtoken"- export
defaultcontains what i need, sign, verify, etc - however, the types won't let me have it
- export
@types/jsonwebtoken- does not have any definition for a default export
as you can see there's an incompatibility between what can actually be imported at runtime, versus what the @types typings allow us to import. on one hand, this could be seen as a deficiency in the community @types typings
on the other hand, a fundamental fix for this problem would be:
- upgrade jsonwebtoken for first-class esm support
- maintain official typings
related issue #655
in the meantime, here's the hack i used to circumvent this problem
-
create a shim module
badmodules/jsonwebtoken.tsimport * as _jsonwebtoken from "jsonwebtoken" const jsonwebtoken = <any>_jsonwebtoken import { sign as signType, verify as verifyType, SignOptions, VerifyOptions, Algorithm, } from "jsonwebtoken" const sign: typeof signType = jsonwebtoken.default.sign const verify: typeof verifyType = jsonwebtoken.default.verify export { sign, verify, Algorithm, SignOptions, VerifyOptions, } -
import the shim module instead
import {sign, verify, SignOptions, VerifyOptions, Algorithm} from "./badmodules/jsonwebtoken.js"
- Lingua principale
- JavaScript
- Stelle
- 18.2k
- Fork
- 1.3k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di auth0/node-jsonwebtoken
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
auth0/node-jsonwebtoken#1042 · 1 commento ·
-
`jwt.sign()` callback is executed twice for "The payload already has an "..." property" errors Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
auth0/node-jsonwebtoken#1000 · 2 commenti · 1 reazione ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 65/100
auth0/node-jsonwebtoken#1046 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
auth0/node-jsonwebtoken#1034 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
auth0/node-jsonwebtoken#1032 ·
Tutte le issue di auth0/node-jsonwebtoken
Issue simili
-
Update HugeIcons library Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
antfu-collective/icones#398 ·
-
ECmail.com Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
wesbos/burner-email-providers#554 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
radiantearth/stac-browser#1023 ·
-
HMR stops working Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
components-web-app/docs#92 ·