node-libxl icon indicating copy to clipboard operation
node-libxl copied to clipboard

"Error: unable to load libxl.node" doesnt show real problem

Open i4got10 opened this issue 11 years ago • 6 comments

Im trying to find the reason why lib not working and add console.log to watch that going wrong

for (var i = 0; i < paths.length; i++) {
    try {
        bindings = require(path.join(paths[i], 'libxl'));
        break;
    } catch (e) {
        console.log(e);
    }
}

first is that paths is [ undefined ], so we can pass it with

var paths = process.env['NODE_LIBXL_PATH'] ? [process.env['NODE_LIBXL_PATH']] : [];

second it could be better to show the truth reason of library fail

        if (e.code !== 'MODULE_NOT_FOUND') {
            throw e;
        }

LOGS

[TypeError: Arguments to path.join must be strings]

{ [Error: Cannot find module '/Users/frgt/Projects/metgen/node_modules/libxl/lib/darwin-x64/libxl'] code: 'MODULE_NOT_FOUND' }

{ [Error: Cannot find module '/Users/frgt/Projects/metgen/node_modules/libxl/lib/darwin/libxl'] code: 'MODULE_NOT_FOUND' }

{ [Error: Cannot find module '/Users/frgt/Projects/metgen/node_modules/libxl/build/Debug/libxl'] code: 'MODULE_NOT_FOUND' }

[Error: dlopen(/Users/frgt/Projects/metgen/node_modules/libxl/build/Release/libxl.node, 1): Library not loaded: libxl.dylib
  Referenced from: /Users/frgt/Projects/metgen/node_modules/libxl/build/Release/libxl.node
  Reason: image not found]

i4got10 avatar Nov 21 '14 09:11 i4got10

Hi Alexey!

Thanks for spotting the glitch in the handling of the environment variable, I fixed it. As for the other change you the suggest, I see the problem, but I would prefer a more robust solution that still tries to exhaust all possibilities before failing. Any suggestions? Otherwise, I'll try to think about something a bit more robust later when I find time ;)

Cheers -Christian

DirtyHairy avatar Nov 21 '14 11:11 DirtyHairy

Thanks Christian! Its just a suggestion from my side.

i4got10 avatar Nov 21 '14 12:11 i4got10

y cual es la solución?

chidalgogalvez avatar Aug 19 '19 16:08 chidalgogalvez

@DirtyHairy I am confused what is the solution for this too. I am getting the "image not found" error.

I am assuming that "image not found" error is referring to not being able to find /node_modules/libxl/deps/libxl/lib/libxl.dylib. That file does exist though.

gajus avatar Sep 09 '19 19:09 gajus

require('/Users/gajus/Documents/dev/[..]/node_modules/libxl/build/Release/libxl.node');

is giving:

internal/modules/cjs/loader.js:977
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: dlopen(/Users/gajus/Documents/dev/[..]/node_modules/libxl/build/Release/libxl.node, 1): Library not loaded: libxl.dylib
  Referenced from: /Users/gajus/Documents/dev/[..]/node_modules/libxl/build/Release//libxl.node
  Reason: image not found
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:977:18)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)
    at Module.require (internal/modules/cjs/loader.js:830:19)
    at require (internal/modules/cjs/helpers.js:68:18)
    at Object.<anonymous> (/Users/gajus/Documents/dev/[..]/node_modules/libxl/lib/libxl.js:1:1)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)

gajus avatar Sep 09 '19 19:09 gajus

libxl.dylib needs to be copied to the current working directory or path to libxl.dylib must be added to DYLD_LIBRARY_PATH.

Upon second reading, this is clearly explained in https://github.com/DirtyHairy/node-libxl#compilation-phase

gajus avatar Sep 09 '19 19:09 gajus