can't import jsonwebtoken in modern typescript esm app
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- node.js, typescript
调研方向
没有指定文件或测试。先从导入示例和相关 issue #655 开始,然后检查该包当前的模块导出和声明设置。完成的标准是:现代 TypeScript ESM 应用无需 shim 即可导入 sign、verify 及其选项类型,并且运行时行为与类型定义一致。
由索引模型根据 Issue 内容生成。
描述
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"
- 主要语言
- JavaScript
- 星标
- 18.2k
- 派生
- 1.3k
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
auth0/node-jsonwebtoken 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
auth0/node-jsonwebtoken#1042 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
auth0/node-jsonwebtoken#1000 · 2 条评论 · 1 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 65/100
auth0/node-jsonwebtoken#1046 ·
-
难度 5/5 一周以上 新手友好度 10/100
auth0/node-jsonwebtoken#1034 ·
-
难度 3/5 1-2 天 新手友好度 48/100
auth0/node-jsonwebtoken#1032 ·
查看 auth0/node-jsonwebtoken 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
antfu-collective/icones#398 ·
-
ECmail.com 未关闭
难度 1/5 1 小时以内 新手友好度 90/100
wesbos/burner-email-providers#554 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
radiantearth/stac-browser#1023 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
components-web-app/docs#92 ·