Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Importing `decode` function from jsonwebtoken causes error

Aperta
#954 6 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript, vite
Ambito
web-dev

Direzione di ricerca

Riproduci l'importazione nella configurazione segnalata con Svelte 4.0.5/Vite 4.4.2 e Chrome. Inizia da node_modules/safe-buffer/index.js e segui lo stack attraverso jws/lib/sign-stream.js, jsonwebtoken/decode.js e jsonwebtoken/index.js; il lavoro è completato quando l'importazione di decode non genera più l'errore del browser segnalato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

Provide a clear and concise description of the issue, including what you expected to happen.

Importing decode function from jsonwebtoken causes error. I am unable to import the 'decode' function as normal.

I suspect that this is an issue with vite and svelte. Seems the package safe-buffer, that jsonwebtoken is dependant on, is doing something vite doesn't like saying Module externalized for browser compatibility meaning it is likely using a Node.js module that is not polyfilled in and the vite doesn't accept. That is just my guess. (See vite info on issue here. )

If you make node-jsonwebtoken work with strict mode with all it's dependencies, this may fix this probelm.

Reproduction

In my code I used the following:

import { decode, sign } from 'jsonwebtoken';

I get the following errors:

app.js:28 TypeError: Cannot read properties of undefined (reading 'from')
    at node_modules/safe-buffer/index.js (jsonwebtoken.js?v=1203475a:28:17)
    at __require (chunk-34KZWS7D.js?v=08cf2519:5:50)
    at node_modules/jws/lib/sign-stream.js (jsonwebtoken.js?v=1203475a:591:19)
    at __require (chunk-34KZWS7D.js?v=08cf2519:5:50)
    at node_modules/jws/index.js (jsonwebtoken.js?v=1203475a:771:22)
    at __require (chunk-34KZWS7D.js?v=08cf2519:5:50)
    at node_modules/jsonwebtoken/decode.js (jsonwebtoken.js?v=1203475a:804:15)
    at __require (chunk-34KZWS7D.js?v=08cf2519:5:50)
    at node_modules/jsonwebtoken/index.js (jsonwebtoken.js?v=1203475a:4397:15)
    at __require (chunk-34KZWS7D.js?v=08cf2519:5:50)
Screenshot 2024-01-04 at 14 30 17

Looking into the chrome debugger and stopping the code before the error it seems that it has to do with the package safe-buffer that jsonwebtoken is dependant on.

Screenshot 2024-01-04 at 14 29 56
Environment

Using svelte (v4.0.5) with vite (v4.4.2) on macOS and test with Chrome browser (v120).

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di auth0/node-jsonwebtoken

Tutte le issue di auth0/node-jsonwebtoken

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.