Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

can't import jsonwebtoken in modern typescript esm app

未关闭
#785 18 条评论 37 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞

调研方向

没有指定文件或测试。先从导入示例和相关 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 default contains what i need, sign, verify, etc
    • however, the types won't let me have it
  • @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

  1. create a shim module badmodules/jsonwebtoken.ts

    import * 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,
    }
    
  2. import the shim module instead

    import {sign, verify, SignOptions, VerifyOptions, Algorithm}
      from "./badmodules/jsonwebtoken.js"
    
主要语言
JavaScript
星标
18.2k
派生
1.3k
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

auth0/node-jsonwebtoken 的其他 Issue

查看 auth0/node-jsonwebtoken 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。