【发布时间】:2020-03-15 16:47:44
【问题描述】:
这是一个电子应用程序。我正在尝试导入 nodejs http 模块,但执行 require('http') 似乎会加载 stream-http 模块。使用它的地方可能存在依赖关系。我基本上是在尝试在电子应用程序中做http.createServer()。应用是这样设置的...
有一个BrowserWindow 与属性:webPreferences: { nodeIntegration: true, webSecurity: false, }。这个BrowserWindow 渲染器有一个反应组件,在构造函数的某处有这个语句:console.log(require('http'));
输出如下所示:
{request: ƒ, get: ƒ, ClientRequest: ƒ, IncomingMessage: ƒ, Agent: ƒ, …}
Agent: ƒ ()
ClientRequest: ƒ (opts)
IncomingMessage: ƒ (xhr, response, mode, fetchTimer)
METHODS: (26) ["CHECKOUT", "CONNECT", "COPY", "DELETE", "GET", "HEAD", "LOCK", ...
get: ƒ (opts, cb)
globalAgent: push../node_modules/stream-http/index.js.http.Agent {}
request: ƒ (opts, cb)
__proto__: Object
基本上这是加载http-stream 模块。如何显式加载原始 nodejs http 模块?
额外问题:在开发者工具窗口中执行require('http') 会给我原始的nodejs http 模块。这是为什么呢?
【问题讨论】:
标签: node.js reactjs electron require