Typescript NPM 制包/发包问题解析
Typescript NPM 制包/发包问题解析
建议点击 查看原文 查看最新内容。
原文链接: https://typonotes.com/posts/2025/03/01/intro-of-npm-package-publish/
NPM 发包
npm 发包必须要注册一个 npm registry 的账号。 包名全局唯一
访问 https://www.npmjs.com/ 并注册一个账号
本地登录
|
|
- 发布
|
|
包的定义
在 package.json
中管理 包的定义
|
|
其他类似 author, license, keywords, repository 等关键字, 可以参考开源公共库 ioredis package.json
NPM 制包: ioredis 单例/集群 客户端
基于 typescript
- 使用
npm init
并安装 typescript 依赖
|
|
配置 tsconfig.json
|
|
moduleResolution
: https://www.typescriptlang.org/tsconfig/#moduleResolution
TroubleShoot
1.
当 tsconfig.json
中的 module 为非 commonjs
的时候, Connot require() ES Module ... in a cycle
错误。
|
|
不知道是否是由于 ioredis
的模式引起的。 参考
ioredis 的 tsconfig.json
之后, 修改为 commonjs
后, 问题解决。
2. IORedisClient is not a constructor
|
|
当没有直接导出 ioredis.ts
的时候, 没有为 commonjs
配置 exports
的时候, 遇到当前问题
解决方法: 创建一个 index.ts
管理 统一导出 的问题。
|
|
2. cylelopp
- 原文链接:https://typonotes.com/posts/2025/03/01/intro-of-npm-package-publish/
- 本文为原创文章,转载注明出处。
- 欢迎 扫码关注公众号
Go与云原生
或 订阅网站 https://typonotes.com/ 。 - 第一时间看后续精彩文章。觉得好的话,请猛击文章右下角「在看」,感谢支持。
