Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Symbol not found: _node_module_register - during dynamic link with better-sqlite3 #1155

Closed
Light-Keeper opened this issue Apr 29, 2021 · 13 comments

Comments

@Light-Keeper
Copy link

Light-Keeper commented Apr 29, 2021

versions and tools invovled

  • Node 14.16.1, installed by asdf
  • pkg 5.1.0
  • better-sqlite3 7.1.15
  • target - node14-macos-x64

Here is an example that fails - https://github.com/Light-Keeper/minimal-pkg

pkg --target node14-macos-x64 ./index.js - executes well, creates index binary. But when I run it, there is an error:

➜  minimal-pkg git:(main) ./index
dyld: lazy symbol binding failed: Symbol not found: _node_module_register
  Referenced from: /Users/vyanushkevich/Projects/test/minimal-pkg/node_modules/better-sqlite3/build/Release/better_sqlite3.node
  Expected in: flat namespace

dyld: Symbol not found: _node_module_register
  Referenced from: /Users/vyanushkevich/Projects/test/minimal-pkg/node_modules/better-sqlite3/build/Release/better_sqlite3.node
  Expected in: flat namespace

[1]    73829 abort      ./index

According to this output, the .node file has been found. but, it depends on _node_module_register symbol that should be exported from node executable, but is not actually exported from the prebuilt node binary.

Here are exported symbols from the app built with pkg:

nm ./index | wc -l
4025

nm ./index | grep node_module_register # - empty outout

The same for the original node binary:

nm /Users/vyanushkevich/.asdf/installs/nodejs/14.16.1/bin/node | wc -l
72543

nm /Users/vyanushkevich/.asdf/installs/nodejs/14.16.1/bin/node | grep node_module_register
000000010007f520 T _node_module_register

I've tried renaming executable to nodejs and moving .node file next to the executable, but it did not have any effect.

Any ideas on how to overcome this?

@umonaca
Copy link

umonaca commented May 1, 2021

Same here. I think the prebuilt binary for node-v14.16.1-macos-x64 provided by pkg could be broken.

@umonaca
Copy link

umonaca commented May 1, 2021

I workaround the bug by reverting pkg to v4.5.1. The old prebuilt node binary fetched-v14.4.0-macos-x64, which is inside `` ~/.pkg-cache/v2.6 works well.

@rnreekez
Copy link

rnreekez commented May 3, 2021

Ran into this as well with note-fibers. Thanks for opening this issue so know I wasn't alone. Rolling back to 4.5.1 worked for me as well. As an aside, I attempted a manual re-compile with the same result just in case it was a one-off bad pre-compiled build but no luck, not sure what the resolution might be with 14.16.1

@robertsLando
Copy link
Contributor

@erossignon any clue?

@guymguym
Copy link

guymguym commented May 9, 2021

Reproduced to me too - any idea how to resolve?

$ node -v
v14.16.0
$ pkg --version
5.1.0
$ prebuild-install --version
6.1.2
$ jq .pkg package.json
{
  "outputPath": "build",
  "targets": [
    "macos",
    "linux"
  ],
  "assets": [
    "node_modules/**/*.node",
    "build/**/*.node"
  ]
}

$ pkg . --public
> [email protected]
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=darwin)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)
prebuild-install WARN install No prebuilt binaries found (target=v14.16.1 runtime=node arch=x64 libc= platform=linux)

$ ./build/noobaa-core-macos
dyld: lazy symbol binding failed: Symbol not found: _napi_module_register
  Referenced from: /var/folders/1s/52g85bgj3wlchqh6szld3fp40000gn/T/f2e40016d01c60e8913da09524e6322533f0a40147a7871226a7f82bd016a877/node.napi.node
  Expected in: flat namespace

dyld: Symbol not found: _napi_module_register
  Referenced from: /var/folders/1s/52g85bgj3wlchqh6szld3fp40000gn/T/f2e40016d01c60e8913da09524e6322533f0a40147a7871226a7f82bd016a877/node.napi.node
  Expected in: flat namespace

Abort trap: 6

@justgook
Copy link

MacOS 10.15
got same problem when building with 5.1.0 node-gyp example

  1. enter folder
  2. npm install (that builds binary file)
  3. npx [email protected] hello.js
    got - dyld: lazy symbol binding failed: Symbol not found: _napi_module_register

with npx [email protected] - all works as expected

@jesec
Copy link
Contributor

jesec commented May 21, 2021

This issue has been resolved in 5.2.0. Please let me know if it is still relevant.

@jesec jesec closed this as completed May 21, 2021
@konsumer
Copy link

konsumer commented Jul 31, 2021

With [email protected] I get same issue, with webmidi@next and similar errors with node-midi.

I make a simple script like this:

const { WebMidi } = require('webmidi')

function onEnabled () {
  console.log(WebMidi.inputs)
  console.log(WebMidi.outputs)
}

WebMidi
  .enable()
  .then(onEnabled)
  .catch(console.error)

Build runs without error:

npx pkg@latest miditest.cjs

> [email protected]
> Targets not specified. Assuming:
  node16-linux-x64, node16-macos-x64, node16-win-x64

then I run it and get this:

dyld: lazy symbol binding failed: Symbol not found: _napi_module_register
  Referenced from: /Users/konsumer/Documents/otherdev/miditest/node_modules/jazz-midi/bin/macos64/jazz.node
  Expected in: flat namespace

dyld: Symbol not found: _napi_module_register
  Referenced from: /Users/konsumer/Documents/otherdev/miditest/node_modules/jazz-midi/bin/macos64/jazz.node
  Expected in: flat namespace

[1]    12024 abort      ./dist/miditest-macos

Same issue if I put jazz.node in the same dir.

@bd-joseph-luttrell
Copy link

I'm still getting same issue with aws-crt lib using [email protected]

dyld: lazy symbol binding failed: Symbol not found: _napi_module_register
  Referenced from: /redacted/node_modules/aws-crt/dist/bin/darwin-x64/aws-crt-nodejs.node
  Expected in: flat namespace

dyld: Symbol not found: _napi_module_register
  Referenced from: /redacted/node_modules/aws-crt/dist/bin/darwin-x64/aws-crt-nodejs.node
  Expected in: flat namespace

@woodfe
Copy link

woodfe commented Aug 12, 2021

Got the same error:
dyld: lazy symbol binding failed: Symbol not found: _node_module_register
Referenced from: /Users/user/roadster/node_modules/better-sqlite3/build/Release/better_sqlite3.node
Expected in: flat namespace

@giladdarshan
Copy link

I got the same error using [email protected] while building Node.js v16.4.1 from source

dyld: lazy symbol binding failed: Symbol not found: _napi_module_register
  Referenced from: /path/to/nodeFile.node
  Expected in: flat namespace

dyld: Symbol not found: _napi_module_register
  Referenced from: /path/to/nodeFile.node
  Expected in: flat namespace

The issue was caused (at least for me) by pkg enabling the Link Time Optimization flag during configuration, I've removed line 47 from pkg-fetch's build file, ran through the workflow again and was able to run the application without errors.
File location locally for testing is /usr/local/lib/node_modules/pkg/node_modules/pkg-fetch/lib-es5/build.js

jesec added a commit to jesec/node that referenced this issue Aug 22, 2021
man ld -export_dynamic:

```
Preserves all global symbols in main executables during LTO.

Without this option, Link Time Optimization is allowed to inline
and remove global functions.

This option is used when a main executable may load a plug-in which
requires certain symbols from the main executable.
```

Bug: vercel/pkg#1155
Signed-off-by: Jesse Chan <[email protected]>
jesec added a commit to vercel/pkg-fetch that referenced this issue Aug 24, 2021
@borgen12
Copy link

I am also getting this error for two different targets: ["node12-macos-x64", "node14-windows-x64"], the error looks to be getting thrown from my node modules.

@maka-io
Copy link

maka-io commented Sep 1, 2021

I also have been getting this problem with my module using [email protected]:

dyld: lazy symbol binding failed: Symbol not found: _node_module_register
  Referenced from: /.../node_modules/fibers/bin/darwin-x64-83/fibers.node
  Expected in: flat namespace

dyld: Symbol not found: _node_module_register
  Referenced from: /.../node_modules/fibers/bin/darwin-x64-83/fibers.node
  Expected in: flat namespace

lpinca pushed a commit to nodejs/node that referenced this issue Sep 5, 2021
man ld -export_dynamic:

```
Preserves all global symbols in main executables during LTO.

Without this option, Link Time Optimization is allowed to inline
and remove global functions.

This option is used when a main executable may load a plug-in which
requires certain symbols from the main executable.
```

Bug: vercel/pkg#1155
Signed-off-by: Jesse Chan <[email protected]>

PR-URL: #39839
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
targos pushed a commit to nodejs/node that referenced this issue Sep 7, 2021
man ld -export_dynamic:

```
Preserves all global symbols in main executables during LTO.

Without this option, Link Time Optimization is allowed to inline
and remove global functions.

This option is used when a main executable may load a plug-in which
requires certain symbols from the main executable.
```

Bug: vercel/pkg#1155
Signed-off-by: Jesse Chan <[email protected]>

PR-URL: #39839
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
richardlau pushed a commit to nodejs/node that referenced this issue Sep 10, 2021
man ld -export_dynamic:

```
Preserves all global symbols in main executables during LTO.

Without this option, Link Time Optimization is allowed to inline
and remove global functions.

This option is used when a main executable may load a plug-in which
requires certain symbols from the main executable.
```

Bug: vercel/pkg#1155
Signed-off-by: Jesse Chan <[email protected]>

PR-URL: #39839
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests