Skip to main content

Node.js 本地插件与 Electron 5.0

· 4 min read

如果你在 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 Request!)可能是你最好的选择。

🌐 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.