Node.js 原生插件和 Electron 5.0
如果你在 Electron 5.0 中使用原生 Node.js 插件时遇到问题,则可能需要更新它才能与最新版本的 V8 引擎兼容。
¥If you're having trouble using a native Node.js addon with Electron 5.0, there's a chance it needs to be updated to work with the most recent version of V8.
告别 v8::Handle
,迎接 v8::Local
¥Goodbye v8::Handle
, Hello v8::Local
2014 年,V8 团队弃用了 v8::Handle
,转而使用 v8::Local
作为本地句柄。Electron 5.0 包含一个 V8 版本,该版本最终彻底移除了 v8::Handle
,仍在使用该版本的原生 Node.js 插件需要更新才能与 Electron 5.0 一起使用。
¥In 2014, the V8 team deprecated v8::Handle
in favor of v8::Local
for local handles. Electron 5.0 includes a version of V8 that has finally removed v8::Handle
for good, and native Node.js addons that still use it will need to be updated before they can be used with Electron 5.0.
所需的代码更改很少,但每个仍在使用 v8::Handle
的原生 Node 模块都将无法使用 Electron 5.0 构建,需要进行修改。好消息是,Node.js v12 也将包含这项 V8 更改,因此任何使用 v8::Handle
的模块都需要更新才能与即将发布的 Node 版本兼容。
¥The required code change is minimal, but every native Node module that still uses v8::Handle
will fail to build with Electron 5.0 and will need to be modified. The good news is that Node.js v12 will also include this V8 change, so any modules that use v8::Handle
will need to be updated anyway to work with the upcoming version of Node.
我维护一个原生插件,可以帮忙吗?
¥I maintain a native addon, how can I help?
如果你维护 Node.js 的原生插件,请确保将所有出现的 v8::Handle
替换为 v8::Local
。前者只是后者的别名,因此无需进行其他更改即可解决此特定问题。
¥If you maintain a native addon for Node.js, ensure you replace all occurrences of v8::Handle
with v8::Local
. The former was just an alias of the latter, so no other changes need to be made to address this specific issue.
你可能还想了解一下 N-API,它作为 Node.js 的一部分,独立于 V8 进行维护,旨在将原生插件与底层 JavaScript 引擎的变化隔离开来。你可以在 在 Node.js 网站上的 N-API 文档中 中找到更多信息。
¥You may also be interested in looking into N-API, which is maintained separately from V8 as a part of Node.js itself, and aims to insulate native addons from changes in the underlying JavaScript engine. You can find more information in the N-API documentation on the Node.js website.
求助!我在我的应用中使用了一个原生插件,但它无法运行!
¥Help! I use a native addon in my app and it won't work!
如果你在应用中使用了 Node.js 的原生插件,并且该原生插件由于此问题而无法构建,请与该插件的作者联系,看看他们是否发布了修复此问题的新版本。如果无法解决,联系作者(或 正在提交 Pull 请求!)可能是你最好的选择。
¥If you're consuming a native addon for Node.js in your app and the native addon will not build because of this issue, check with the author of the addon to see if they've released a new version that fixes the problem. If not, reaching out to the author (or opening a Pull Request!) is probably your best bet.