什么是上下文感知的插件
发布于 4 年前 作者 muyoucun557 6388 次浏览 来自 问答

下面是关于“上下文感知插件”的文档 There are environments in which Node.js addons may need to be loaded multiple times in multiple contexts. For example, the Electron runtime runs multiple instances of Node.js in a single process. Each instance will have its own require() cache, and thus each instance will need a native addon to behave correctly when loaded via require(). From the addon’s perspective, this means that it must support multiple initializations.

Node.js 插件可能需要在多个上下文中多次加载的环境。 比如,Electron 的运行时会在单个进程中运行多个 Node.js 实例。 每个实例都有它自己的 require() 缓存,因此当通过 require() 进行加载时,每个实例需要一个原生的插件才能正常运行。 从插件程序的角度来看,这意味着它必须支持多次初始化。

请教下,针对上述文档的最后一句, 从插件程序的角度来看,这意味着它必须支持多次初始化。是什么意思?

2 回复

大概就是每次require 的模块都是一个新实例,避免相互干扰

Uncaught Error: Loading non-context-aware native module in renderer: '\\?\xxxxxxx\node_modules\@serialport\bindings\build\Release\bindings.node', but app.allowRendererProcessReuse is true.

为了使用serialport,如今还在用electron5.0

回到顶部