anothersmith / node-duckdb

DuckDB NodeJS bindings
MIT License
48 stars 12 forks source link

Cannot load @rpath/libduckdb.dylib #69

Closed jpkli closed 3 years ago

jpkli commented 3 years ago

Thank you for sharing this awesome work!

I tried to use node-duckdb, but encountered the following error when using with webpack 5.x and node-loader on Mac OS:

Error: Cannot open /..../build/node-duckdb-addon.node: Error: dlopen(/..../build/node-duckdb-addon.node, 1): Library not loaded: @rpath/libduckdb.dylib
  Referenced from: /.../build/node-duckdb-addon.node
  Reason: image not found
    at Object.../../node_modules/node-duckdb/build/Release/node-duckdb-addon.node (node-duckdb-addon.node:1)

I have to manually copy the "libduckdb.dylib" from the node_modules/node-duckdb/build/Release folder to my build folder to work around this error. It would be great if this can be fixed. Thanks again!

rprovodenko commented 3 years ago

Hi, thanks for the feedback. I believe this is a node-loader issue, since it should automatically resolve all the dependencies (like ncc does for example). But nevertheless, my proposed workaround is to use the copy-webpack-plugin:

const path = require('path');
const CopyPlugin = require("copy-webpack-plugin");

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist'),
  },
  target: 'node',
  node: {
    __dirname: false,
  },
  plugins: [
    new CopyPlugin({
      patterns: [
        { from: "**/*.dylib", to: "[name].[ext]" },
      ],
    }),
  ],
  module: {
    rules: [
      {
        test: /\.node$/,
        loader: 'node-loader',
      },
    ],
  },
};

I'm going to add this to the readme.

jpkli commented 3 years ago

Thank you! We're already using the copy-plugin as a workaround for now.