openpeeps / denim

Node 💖 Nim = Denim! Build powerful NodeJS / BunJS addons with Nim language via Node API (NAPI)
https://openpeeps.github.io/denim/
MIT License
40 stars 1 forks source link

Can't use add-on in an external project #7

Closed jfilby closed 1 year ago

jfilby commented 1 year ago

I successfully build an add-on, but when I copy it to an external project, I can't get it to load. This is a Next.js project. Every technique I try encounters a different error.

Do I need to wait for the ability to build an npm from the add-on?

georgelemon commented 1 year ago

Maybe you need Webpack node-loader? Or something similar but for Babel

jfilby commented 1 year ago

I'm using an npm called nextjs-node-loader, which gets further, but the module doesn't load because I don't have glibc_2.34.

The requirement for glibc_2.34 seems to come from the compiled addon.

I've retested and I get the same error in the package directory where I use Denim. I'm not sure if this is from a snap that auto-updated itself and broke something. I'll investigate some more. It worked a day or two ago.

Loading with Bun is also suddenly broken, with an undefined symbol: cmdLine error.

I've now updated to Node v20 and I get the same error that Bun gives, but with a little bit more context before that:

node:internal/modules/cjs/loader:1343
  return process.dlopen(module, path.toNamespacedPath(filename));

Error: /full-path/...my-module.node: undefined symbol: cmdLine

I commented out everything and slow uncommented various lines in my Nim package. It turns out that importing jester causes this problem. I use it in some shared code. It's possible to not use it, but it will take me a bit of time to separate the code. I'll continue on this tomorrow.

jfilby commented 1 year ago

I got it working by:

  1. Using nextjs-node-loader for the Next.js I'm using the addon in. Node-loader tried to find the addon as a shared library in a path and filename that didn't exist. Node-bindings had a bug that gave an indexOf undefined error.
  2. Using Node v20. I had a glibc_2.34 not found error with v18, I'm not sure if that would've been eliminated with the next step.
  3. Removing any imports of the jester package from my addon. I was importing code from my Nexus package that did this to check headers and submitted form fields.
  4. I import the functions from the addon using a relative path. I had to add an @ts-ignore annotation above the import to silence a VSCode warning that the import couldn't be found.