Level / leveldown

Pure C++ Node.js LevelDB binding. An abstract-leveldown compliant store.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No native build was found in electron

vaultec81 opened this issue · comments

Hello. It appears that I have found an issue with leveldown's native bindings in nodejs. I have attempted to clean node_modules cache, install/reinstall node-gyp and windows build tools, change version of VS. All in vain. I am using leveldown in a electron main process instance both renderer and main process. However, when running in developer mode there is no problems. When compiling electron into a binary (tested both electron-packager, and electron-builder) the issue is present. It appears that leveldown, and other native dependencies compile correct when running npm install and packaging the project. This issue only seems to effect leveldown, other native dependencies works without issue such as secp256k1. I have ran this code another windows machine confirming there is no environmental settings that could play a role.

  • OS: Windows 10 (10.0.18363) 64 bit
  • Electron: 9.0.4, and 8.3.2 tested.
  • Node: v12.18.0

Similar issue on the electron repo, although not specified whether the problem is coming from leveldown electron/electron#20075
NOTE: At the moment I do not have enough information to conclude whether this is specifically an issue with electron or leveldown. But most likely leveldown is the culprit.

When running in main process
Error with leveldown

When running in renderer

No native build was found for platform=win32 arch=x64 runtime=electron abi=76 uv=1 libc=glibc
    at Function.load.path (webpack-internal:///382:47)
    at load (webpack-internal:///382:22)
    at eval (webpack-internal:///71:1)
    at Object.<anonymous> (renderer.prod.js:1)
    at N (renderer.prod.js:1)
    at eval (webpack-internal:///371:5)
    at Object.<anonymous> (renderer.prod.js:1)
    at N (renderer.prod.js:1)
    at eval (webpack-internal:///409:17268)
    at Module.<anonymous> (renderer.prod.js:1)

@vaultec81 Could you share something we can use to try reproducing this? I'm fairly positive @vweevers has a windows 64 bit machine.

Quick thoughts:

  • Check that the native addon (*.node) gets included in your ASAR archive. Either a prebuilt binary (at e.g. node_modules/leveldown/prebuilds/win32-x64/...) or one built from source (at e.g. node_modules/leveldown/build/Release/leveldown.node)
  • If so, this should work for at least the main Electron process. On first access of the native addon, Electron will unpack it to a temporary file, and then load it.
  • If you prefer not to use temporary files (which aren't automatically cleaned up) then you could try the asarUnpack option, assuming you're using electron-builder. Usage stays the same.
  • As for the renderer processes, this is likely an issue with webpack.
  • In case you are also bundling your JS for the main Electron process: check that __dirname behaves correctly, because resolving the native addon depends on it.

fix found here with webpack. Thank you for your responses.

I'm getting a similar issue, but on Linux this time.
It happens when I try to create an IPFS node. Happens in development mode.

Error: No native build was found for platform=linux arch=x64 runtime=electron abi=80 uv=1 libc=glibc
    at Function.load.path (webpack:///./node_modules/leveldown/node_modules/node-gyp-build/index.js?:56:9)
    at load (webpack:///./node_modules/leveldown/node_modules/node-gyp-build/index.js?:20:30)
    at eval (webpack:///./node_modules/leveldown/binding.js?:1:124)
    at Object../node_modules/leveldown/binding.js (~/project/dist_electron/index.js:11470:1)
    at __webpack_require__ (~/project/dist_electron/index.js:20:30)
    at eval (webpack:///./node_modules/leveldown/leveldown.js?:3:17)
    at Object../node_modules/leveldown/leveldown.js (~/project/dist_electron/index.js:11503:1)
    at __webpack_require__ (~/project/dist_electron/index.js:20:30)
    at eval (webpack:///./node_modules/datastore-level/node_modules/level/level.js?:1:111)
    at Object../node_modules/datastore-level/node_modules/level/level.js (~/project/dist_electron/index.js:2542:1)

@giraffekey What's strange in that stack trace is that it seems to load both level-js and leveldown. That code is running in the electron main process (rather than a renderer process), correct? In which case you'll want to disable package.browser resolution in webpack. The notes above (#725 (comment)) apply here as well (specifically about __dirname).

/cc @achingbrain because it's datastore-level

Yes, it's main process. I've found it works perfectly fine under a normal Electron setup, it must be something caused by Vue's electron-builder plugin.

I've since refactored my codebase and gotten rid of electron-builder's boilerplate so I'm not having this issue anymore. If you would like to recreate this issue for examination, use the vue create command and vue add electron-builder to generate the boilerplate I was using, then attempt to spawn an IPFS node in the main process with ipfs.create() from the ipfs library.

commented

add webpack
target: 'electron-main'
node: {
global: true,
__dirname: true,
__filename: true
}

Same problem with me but the solution is a little different.

Fix found add externals: ['level'] and make sure that level under dependencies,not devDependencies

😂😂