-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用了 global 变量、http 模块,不兼容浏览器端使用 #2
Comments
middleware.ts 这个看名字就知道是给 express.js 用的中间件了,不会引入到浏览器的。nisper 已经用到线上网页项目一年多了,不可能有这么严重的浏览器有问题的。 https://github.com/ysmood/nisper/blob/master/lib/index.ts#L10 关于这个,你需要学习下 typescript,这个只是 type 引用,并没有实际引入代码 😂 |
[email protected] 包里的代码,这在浏览器里不报错?: var middleware_1 = require("./middleware");
var http_1 = require("http");
exports.ServerRequest = http_1.ServerRequest;
exports.ServerResponse = http_1.ServerResponse;
......
middleware: middleware_1["default"](opts), middleware: |
嗯,确实有问题。 看了下代码,这个项目发布的时候会用 webpack 编译,webpack 会自动引入 http 库,这个逻辑源自当年的 browserify ,所以不会报错,只是引入了一大块无用代码。但是如果你不用 webpack 确实可能会出错。 |
修正了,这两行当时加入仅仅是为了 typescript 的 type 提示,删掉没任何影响,发布了 v0.8.3 |
非常感谢你的提示。 实际上这个是 typescript 没能实现的 feature: 我以为纯 type import 不会实际编译出 require,但实际上不是如此,巧合的是 webpack 自动引入才一直没事 |
真快,赞 |
项目中使用了 Node 中才有的 API,除非浏览器端 mock 这些 API 才能正常使用
The text was updated successfully, but these errors were encountered: