Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node binding on mac return undefiend #171

Open
lake2 opened this issue Mar 1, 2025 · 4 comments
Open

node binding on mac return undefiend #171

lake2 opened this issue Mar 1, 2025 · 4 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@lake2
Copy link

lake2 commented Mar 1, 2025

const getRuntimePlatformArch = () => `${process.platform}-${process.arch}`;

/**
 * @throw Error if there isn't any available native binding for the current platform/arch.
 */
const getNativeNodeBinding = (runtimePlatformArch) => {
    switch(runtimePlatformArch) {
        case `linux-x64`:
            return require('@duckdb/node-bindings-linux-x64/duckdb.node');
        case 'linux-arm64':
            return require('@duckdb/node-bindings-linux-arm64/duckdb.node');
        case 'darwin-arm64':
         {
            const a = require('@duckdb/node-bindings-darwin-arm64/duckdb.node')
            console.log('',JSON.stringify(a))
            return a ;
         }
        case 'darwin-x64':
            return require('@duckdb/node-bindings-darwin-x64/duckdb.node');
        case 'win32-x64':
            return require('@duckdb/node-bindings-win32-x64/duckdb.node');
        default:
            const [platform, arch] = runtimePlatformArch.split('-')
            throw new Error(`Error loading duckdb native binding: unsupported arch '${arch}' for platform '${platform}'`);
    }
}

module.exports = getNativeNodeBinding(getRuntimePlatformArch());

output:

 {}

chip: Apple M3 Pro
macOS: 14.7.1 (23H222)

@jraymakers
Copy link
Contributor

Could you say more about the scenario in which you encountered this? For example, how are you running your Node program? What are the values of process.platform and process.arch in your environment? What's in your package.json? Is the package @duckdb/node-bindings-darwin‐arm64 in your node_modules? If so, does it contain duckdb.node?

@lake2
Copy link
Author

lake2 commented Mar 2, 2025

Could you say more about the scenario in which you encountered this? For example, how are you running your Node program? What are the values of process.platform and process.arch in your environment? What's in your package.json? Is the package @duckdb/node-bindings-darwin‐arm64 in your node_modules? If so, does it contain duckdb.node?

package.json:

{
  "name": "ai-search-spider",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "tsc --watch"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@duckdb/node-api": "1.2.0-alpha.15",
    "tslib": "^2.8.1"
  },
  "devDependencies": {
    "typescript": "^5.8.2"
  }
}

.npmrc:

shamefully-hoist = true

then execute pnpm i, run index.ts:

import duckdb from '@duckdb/node-api';

console.log(duckdb);

output:

undefined

pnpm verion:10.3.0
nodejs version:20.18.1
process.platform: darwin
process.arch:arm64
node_modules:
Image

@jraymakers
Copy link
Contributor

The problem has to do with the differences in how TypeScript and ES6 handle default imports. Since @duckdb/node-api doesn't (currently) have a default export, in TypeScript you need to write:

import * as duckdb from '@duckdb/node-api'

In JavaScript, you can be more loose, and write:

import duckdb from '@duckdb/node-api'.

This is awkward; I think I can make a change to allow import duckdb from '@duckdb/node-api' in TypeScript.

@jraymakers jraymakers self-assigned this Mar 2, 2025
@jraymakers jraymakers added the bug Something isn't working label Mar 2, 2025
@jraymakers jraymakers added this to the Bugs milestone Mar 2, 2025
@jraymakers
Copy link
Contributor

Merged a fix; will go out with next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants