Importing `decode` function from jsonwebtoken causes error
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript, vite
- Domain
- web-dev
Research direction
Reproduce the import in the reported Svelte 4.0.5/Vite 4.4.2 setup and Chrome. Start with node_modules/safe-buffer/index.js and follow the stack through jws/lib/sign-stream.js, jsonwebtoken/decode.js, and jsonwebtoken/index.js; done means importing decode no longer throws the reported browser error.
Written by the indexing model from the issue text.
Description
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)
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.
Environment
Using svelte (v4.0.5) with vite (v4.4.2) on macOS and test with Chrome browser (v120).
- Dominant language
- JavaScript
- Stars
- 18.2k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from auth0/node-jsonwebtoken
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
auth0/node-jsonwebtoken#1042 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
auth0/node-jsonwebtoken#1000 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 65/100
auth0/node-jsonwebtoken#1046 ·
-
Difficulty 5/5 Over a week Newbie friendliness 10/100
auth0/node-jsonwebtoken#1034 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
auth0/node-jsonwebtoken#1032 ·
All issues in auth0/node-jsonwebtoken
Similar issues
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Automattic/safe-publish#594 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
dream-num/dsh-univer-office#104 ·
-
comp/dashboard invalid P3
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
NousResearch/hermes-agent#121143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
avniproject/avni-webapp#1811 ·
-
area/auroraboot area/webui bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100