Comments (14)
import Mirai from "mirai-ts"
可以啊,我自己正用着呢。
版本是?当前最新版本是 v0.4.5
。
from mirai-ts.
2ce9e92 这里的修改是为了适配 nodejs,以便使用 require("mirai-ts")
而非 require("mirai-ts").default
。
应该不会对 import Mirai from 'mirai-ts'
的语法产生影响。
from mirai-ts.
肯定是最新版本的,但是我这里报错
this.bot = new mirai_ts_1.default({
^
TypeError: mirai_ts_1.default is not a constructor
from mirai-ts.
能否提供一下原项目此处的代码链接?
from mirai-ts.
2ce9e92 这里的修改是为了适配 nodejs,以便使用
require("mirai-ts")
而非require("mirai-ts").default
。应该不会对
import Mirai from 'mirai-ts'
的语法产生影响。
我知道,但是我不是很明白:
- module.exports = Mirai;
- module.exports.default = Mirai;
- module.exports.Mirai = Mirai;
+ exports = module.exports = Mirai;
这两个等价吗?
from mirai-ts.
能否提供一下原项目此处的代码链接?
https://github.com/CL-Jeremy/mirai-twitter-bot/blob/master/src/mirai.ts
from mirai-ts.
这两个等价吗?
exports 是对 module.exports 的引用,只在原生的 nodejs 中我们需要用到 module.exports
。因为 require()
返回的是 module.exports
,而 TypeScript 可以使用 ES6+ 的 import 语法,直接调用 exports 即可。
本质上是:
module.exports = Mirai
exports = module.exports
https://github.com/CL-Jeremy/mirai-twitter-bot/blob/master/src/mirai.ts
我尝试 clone 了您的项目,构建时并没有发现报错提示。重新安装下 node_modules ?
from mirai-ts.
也可能与 node 版本有关,我当前使用的是 nodejs LTS 版本(12.18.3)。
from mirai-ts.
这种诸如 import * as A from 'a';
与 import A from 'a';
的差异在构建时不会体现,可以尝试执行一下 node dist/main.js config.json.example
。
from mirai-ts.
也可能与 node 版本有关,我当前使用的是 nodejs LTS 版本(12.18.3)。
服务器上同为 12.18.3(本机上是 14.x)
from mirai-ts.
5d93693 已同时导出 default 以修复该问题。
已 release v0.4.6。我测试已可以正常运行。
如果没问题的话,可以关闭该 ISSUE。
from mirai-ts.
是不是因为我 tsconfig.json 的设置呢?因为如上面我报错的信息所示,我生成的 JS 在创建时肯定还是在调用 require ('mirai-ts').default
,是否这种情况下必须定义 module.exports.default
呢?
from mirai-ts.
好的,多谢!
from mirai-ts.
是不是因为我 tsconfig.json 的设置呢?因为如上面我报错的信息所示,我生成的 JS 在创建时肯定还是在调用 require ('mirai-ts').default,是否这种情况下必须定义 module.exports.default 呢?
发现 TypeScript 构建后总是使用 .default,而我之所以可以正常使用,是因为我开发的 el-bot 更接近于一个库,导出时会自动加上 __importDefault()
的函数,来适配是否使用 default。
而本质上,你也可以考虑使用导出一个主入口文件的方式来使用,而非直接执行编译后的部分 js 文件。当然这也并非必要的。
主动适配 module.exports.default 显然是更好的方式。
from mirai-ts.
Related Issues (20)
- ts-node 报错 HOT 4
- MessageChain 无法正确发送 HOT 1
- src/mirai-api-http/resp.ts 中注释有误 HOT 1
- mirai-api-http 文档链接指向错误 HOT 2
- `utils/check.ts#match` 函数的实现问题 HOT 2
- 能否发送base64的图片 HOT 2
- "File" message lost in FriendMessage&GroupMessage HOT 3
- V2.0 MiraiApiHttpSetting interface HOT 2
- Member interface broken in the given api HOT 13
- 读取mirai-api-http配置时报错 HOT 3
- API 和最新的 mirai-api-http 相比有缺失 HOT 4
- 建议使用 private 修饰符修饰部分字段 HOT 2
- bot mirai.api.sendGroupMessage 能不能加个代理配置。。。 HOT 2
- export more types HOT 1
- Why “TypeError: Mirai is not a constructor”? HOT 3
- mirai-api-http 更新之后,messageFromId 方法需要传额外的参数,大佬能更新一下版本吗? HOT 6
- 请教一下如何撤回msg.reply回复的消息 HOT 2
- mirai-api-http 更新了字段导致 messageFromId 调用报错,麻烦大佬更新一下~
- MessageType怎么引用? HOT 1
- 部分接口的请求未传递参数
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mirai-ts.