Skip to content

Native Modules headache

Nicolas Ramz edited this page Nov 17, 2019 · 1 revision

Some little problems trying to use native modules...

drivelist

Native module drivelist (or one of its deps) appears to use eval(). Changing the Content-Security-Policy as is fixes the problem, but we don't want this:

    <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-eval'">

electron-rebuild (dev mode)

The drivelist native module has to be rebuilt: electron-rebuild can do that, but it places the drivelist.node build file in node_modules/drivelist/build/darwin-x64-64/drivelist.node and the dev electron doesn't look there so do not find the file.

Manually copying it in one of the searchpath (eg. build/) fixes the problem.

On Windows, the module has first to be rebuilt using:

npm install --save-dev electron-rebuild

# Every time you run "npm install", run this
./node_modules/.bin/electron-rebuild

# On Windows if you have trouble, try:
.\node_modules\.bin\electron-rebuild.cmd

And then the file found inside node_modules\drivelist\bin\win32-x64-64\drivelist.node has to be copied into build.

electron-rebuild (packaged mode)

Built app won't include the built native module and at runtime, following error will appear:

Uncaught (in promise) TypeError: Cannot read property 'indexOf' of undefined

The problem appears to be in bindings or electron-builder, I'm not sure where to look.

Bug opened in bindings: https://github.com/TooTallNate/node-bindings/issues/54

Update: the problem is actually related to the webpack's optimizer that strips some code. See: https://github.com/TooTallNate/node-bindings/issues/61#issuecomment-549383387