question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enhancement: migrate from nan to node-addon-api (N-API)

See original GitHub issue

I’m trying to use this with Electron and run some tests in Node but I absolutely cannot get a working version for each runtime working simultaneously. It always puts the built module into Release\sharp.node, overwriting the previously built version.

If I build for electron, I cannot test. If I build for Node, I cannot run it in Electron.

When I build for Electron, my tests return the following:

The file it says it cannot find does exist

 FAIL  app/redux/sagas/firebase/oneTime/__tests__/helpers.test.js
  ● Test suite failed to run

    The specified module could not be found.
    \\?\C:\projects\myApp\app\node_modules\sharp\build\Release\sharp.node

      Error: The specified module could not be found.
      \\?\C:\projects\myApp\app\node_modules\sharp\build\Release\sharp.node
      at Runtime.requireModule (node_modules/jest-runtime/build/index.js:372:31)
      at Object.<anonymous> (app/node_modules/sharp/lib/constructor.js:10:15)

When I build for Node, my app’s renderer throws this error:

ELECTRON_ASAR.js:172 Uncaught Error: The system cannot find message text for message number 0x%1 in the message file for %2.
\\?\C:\projects\myApp\app\node_modules\sharp\build\Release\sharp.node
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:172:20)
    at Object.Module._extensions..node (module.js:671:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:172:20)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:504:12)
    at Function.Module._load (module.js:496:3)
    at Module.require (module.js:586:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\projects\myApp\app\node_modules\sharp\lib\constructor.js:10:15)
    at Object.<anonymous> (C:\projects\myApp\app\node_modules\sharp\lib\constructor.js:259:3)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

13reactions
lovellcommented, Mar 7, 2020

v0.25.0 now available with the use of N-API. I’m sure the maintainers of the many modules that depend upon sharp will be happy with the reduced level of installation issues this will bring.

6reactions
lovellcommented, Apr 22, 2020

Hello, this is more a current limitation of native modules in Node rather than being a problem specific to sharp.

Different versions of Node and Electron each have different ABIs, hence the need to ensure compilation occurred against the relevant runtime.

Node provides a new ABI-stable N-API that aims to solve this problem. To take advantage of this we need to:

  • Wait for https://github.com/prebuild/prebuild/issues/220 to land
  • Wait for the N-API to be backported as “stable” to Node.js 8 to avoid warnings about its experimental behaviour
  • Wait for Node.js 8 to reach EOL as N-API support is not quite stable enough in that major version.
  • Migrate sharp from nan to node-addon-api
Read more comments on GitHub >

github_iconTop Results From Across the Web

NAN to Node-API Migration: A Short Story - NodeSource
Throughout the years I've created my fair share of native addons. The first ones were created by using the native C++ Node.js and...
Read more >
Migration tutorial · The Node-API Resource - GitHub Pages
The objective of this tutorial is to give you a good idea of the steps necessary and the tools available to migrate an...
Read more >
How We Migrated Realm JavaScript From NAN to N-API
The Realm JavaScript team has reimplemented the Realm JS Node.js SDK from the ground up to use N-API. Here we describe how and...
Read more >
Asynchronous C++ Addon for Node.js with N-API ... - CodeMerx
This method overrides the Napi::AsyncWorker::Execute method and as such will be executed on a worker thread different than the Node.js event ...
Read more >
Migrating old Addons to NAPI - node.js nan - Stack Overflow
n-api is a new way to create addon independent from the underlying JavaScript runtime (ex V8) and is maintained as part of Node.js....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found