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

[email protected]: Failed to find native module for linux-arm64 #472

Closed
4 of 5 tasks
fbarril opened this issue Jan 7, 2024 · 13 comments
Closed
4 of 5 tasks

[email protected]: Failed to find native module for linux-arm64 #472

fbarril opened this issue Jan 7, 2024 · 13 comments
Labels
awaiting feedback Awaiting Feedback from OP bug Indicates an unexpected problem or unintended behavior

Comments

@fbarril
Copy link

fbarril commented Jan 7, 2024

I am getting the following error running inside a docker container on a mac m1.

[03:01:45.022] ERROR (361): [email protected]: Failed to find native module for linux-arm64: TypeError: Cannot read properties of undefined (reading 'pactffiInitWithLogLevel')

    const messagePact = new MessageConsumerPact({
        consumer: 'a.b-service-i',
        provider: 'a.b-provider',
        pactfileWriteMode: 'update', 
        logLevel: 'trace', 
    })

I can provide more info if necessary.

Software versions

  • OS: _e.g. Mac OS sonoma 14.2.1
  • Pact Node version: _e.g. Pact Node v12.1.1
  • Node Version: v16.20.2

Issue Checklist

Please confirm the following:

  • I have upgraded to the latest
  • I have the read the FAQs in the Readme
  • I have triple checked, that there are no unhandled promises in my code
  • I have set my log level to debug and attached a log file showing the complete request/response cycle
  • For bonus points and virtual high fives, I have created a reproduceable git repository (see below) to illustrate the problem

Expected behaviour

Tests running

Actual behaviour

Test breaking trying to create MessageConsumerPact

Steps to reproduce

Follow the pact-js-workshop tutorial on a mac m1.

Relevant log files

[03:01:23.659] ERROR (337): [email protected]: Failed to find native module for linux-arm64: TypeError: Cannot read properties of undefined (reading 'pactffiInitWithLogLevel')

Error: Failed to load native module, try setting LOG_LEVEL=debug for more info
    at initialiseFfi (/home/node/app/node_modules/@pact-foundation/pact-core/src/ffi/index.js:99:15)
    at getFfiLib (/home/node/app/node_modules/@pact-foundation/pact-core/src/ffi/index.js:106:15)
    at makeConsumerMessagePact (/home/node/app/node_modules/@pact-foundation/pact-core/src/consumer/index.js:127:37)
    at new MessageConsumerPact (/home/node/app/node_modules/@pact-foundation/pact/src/messageConsumerPact.js:57:66)
    at Suite.<anonymous> (/home/node/app/test/contract/patientCreated.test.js:10:25)
    at Object.create (/home/node/app/node_modules/mocha/lib/interfaces/common.js:148:19)
    at Object.only (/home/node/app/node_modules/mocha/lib/interfaces/common.js:106:21)
    at Function.context.describe.only (/home/node/app/node_modules/mocha/lib/interfaces/bdd.js:69:27)
    at Object.<anonymous> (/home/node/app/test/contract/patientCreated.test.js:9:10)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
    at Function.Module._load (node:internal/modules/cjs/loader:911:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)
    at async formattedImport (/home/node/app/node_modules/mocha/lib/nodejs/esm-utils.js:7:14)
    at async Object.exports.requireOrImport (/home/node/app/node_modules/mocha/lib/nodejs/esm-utils.js:38:28)
    at async Object.exports.loadFilesAsync (/home/node/app/node_modules/mocha/lib/nodejs/esm-utils.js:91:20)
    at async singleRun (/home/node/app/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at async Object.exports.handler (/home/node/app/node_modules/mocha/lib/cli/run.js:370:5)
@fbarril fbarril added the bug Indicates an unexpected problem or unintended behavior label Jan 7, 2024
@floriank
Copy link
Contributor

floriank commented Jan 9, 2024

I recently ran into this when trying out pact provider verification in an alpine container (ubuntu host). Ultimately, to get more info, you can add a console.log here . Edit: (This is me suggesting adding a console.log to the installed package in node_modules, to be explicit here)

For me, it was glibc missing (which, to no one's surprise is normal under alpine, as it uses muslc 😉).

So, maybe it's a missing system dependency? (i.e. something something brew install glibc ?)

@mefellows
Copy link
Member

Follow the pact-js-workshop tutorial on a mac m1.

You mentioned the issue is in docker, however the workshop doesn't use Docker. It would be ideal if you could please provide a simple reproducible setup that uses Docker. In your description you use the Message Pact interface (also not in the workshop), but presumably this bug will show up with just attempting to construct one of the Pact types.

@mefellows mefellows added the awaiting feedback Awaiting Feedback from OP label Jan 9, 2024
@mefellows
Copy link
Member

OK, so I reproduced it.

index.js:

const pact = require('@pact-foundation/pact')
const messagePact = new pact.MessageConsumerPact({
  consumer: 'a.b-service-i',
  provider: 'a.b-provider',
  pactfileWriteMode: 'update', 
  logLevel: 'trace', 
})

Running it in Docker as so:

docker run --rm -it -v $(pwd):/app --entrypoint /bin/sh  node:16
cd /app
node index.js

The error above is reproduced.

Once I shelled into the container and set export LOG_LEVEL=trace, running node index.js gives the following output

# LOG_LEVEL=trace node index.js
[11:38:45.763] DEBUG (448): [email protected]: We detected your platform as:

 - linux-arm64
[11:38:49.187] TRACE (448): [email protected]: Initiliasing ffi for the first time
[11:38:49.188] DEBUG (448): [email protected]: Initalising native core at log level 'trace'
[11:38:49.189] DEBUG (448): [email protected]: binding path #0: : attempting to load native module from:

 - /app/node_modules/@pact-foundation/pact-core/prebuilds/linux-arm64
   source: pact-js-core binding lookup

 - You can override via PACT_PREBUILD_LOCATION

[11:38:49.240] DEBUG (448): [email protected]: binding path #1: : attempting to load native module from:

 - /app/prebuilds/linux-arm64
   source: pact-js-core binding lookup

 - You can override via PACT_PREBUILD_LOCATION

[11:38:49.247] DEBUG (448): [email protected]: Supported platforms are:
 - darwin-arm64
 - darwin-x64
 - linux-arm64
 - linux-x64
 - win32-x64
[11:38:49.247] ERROR (448): [email protected]: Failed to find native module for linux-arm64: TypeError: Cannot read properties of undefined (reading 'pactffiInitWithLogLevel')
[11:38:49.247] DEBUG (448): [email protected]: We looked for a supported build in this location /app/node_modules/@pact-foundation/pact-core/prebuilds/linux-arm64
[11:38:49.247] DEBUG (448): [email protected]: We looked for a supported build in this location /app/prebuilds/linux-arm64
[11:38:49.248] DEBUG (448): [email protected]: Tip: check there is a prebuild for linux-arm64

          check the path exists

      Wrong Path?: set the load path with PACT_PREBUILD_LOCATION ensuring that $PACT_PREBUILD_LOCATION/prebuilds/linux-arm64 exists

      - Note: You dont need to include the prebuilds/linux-arm64 part of the path, just the parent directory

      - Let us know: We can add more supported path lookups easily, chat to us on slack or raise an issue on github
/app/node_modules/@pact-foundation/pact-core/src/ffi/index.js:99
        throw new Error(`Failed to load native module, try setting LOG_LEVEL=debug for more info`);
        ^

Error: Failed to load native module, try setting LOG_LEVEL=debug for more info
    at initialiseFfi (/app/node_modules/@pact-foundation/pact-core/src/ffi/index.js:99:15)
    at getFfiLib (/app/node_modules/@pact-foundation/pact-core/src/ffi/index.js:106:15)
    at makeConsumerMessagePact (/app/node_modules/@pact-foundation/pact-core/src/consumer/index.js:127:37)
    at new MessageConsumerPact (/app/node_modules/@pact-foundation/pact/src/messageConsumerPact.js:57:66)
    at Object.<anonymous> (/app/index.js:2:21)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
    at Function.Module._load (node:internal/modules/cjs/loader:911:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)

Following the advice, I've checked the shared library itself. Using ld to introspect the symbol table, we can see it has a dependency on glibc 2.29:

# ld /app/node_modules/@pact-foundation/pact-core/prebuilds/linux-arm64/libpact_ffi.so
ld: warning: cannot find entry symbol _start; not setting start address
ld: /app/node_modules/@pact-foundation/pact-core/prebuilds/linux-arm64/libpact_ffi.so: undefined reference to `pow@GLIBC_2.29'

As per this issue, we should support back to 2.24, so I think something has changed in that build.

I'm not sure if it's a possibility for you, but the node:18 image does work.

Node 16 is currently EOL and it's not technically supported by us anymore, however if we are able to compile a native lib with a lower version it should resolve this. I'll leave it open to track that.

@fbarril
Copy link
Author

fbarril commented Jan 10, 2024

With node 20 works fine

@mefellows
Copy link
Member

Yep, 18 or later should do the trick

@YOU54F
Copy link
Member

YOU54F commented Feb 9, 2024

Thanks for the report. we downgraded the version of cross which we are using to build the shared library which now means it is linking to glibc 2.23

Tested this on a mac m1 arm64 container as per Matt's steps above and it is now passing on a node 16 (and 14) image

# node index.js
[16:06:24.604] DEBUG (58): [email protected]: We detected your platform as:

 - linux-arm64
[16:06:24.872] TRACE (58): [email protected]: Initiliasing ffi for the first time
[16:06:24.872] DEBUG (58): [email protected]: Initalising native core at log level 'trace'
[16:06:24.872] DEBUG (58): [email protected]: binding path #0: : attempting to load native module from:

 - /app/node_modules/@pact-foundation/pact-core/prebuilds/linux-arm64
   source: pact-js-core binding lookup

 - You can override via PACT_PREBUILD_LOCATION

[16:06:24.875] INFO (58): 0.4.15: pact native library successfully found, and the correct version
2024-02-09T16:06:24.876471Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact - ref = 1, keys = [1]
2024-02-09T16:06:24.876496Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact before - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "a.b-service-i" }, provider: Provider { name: "a.b-provider" }, interactions: [], metadata: {"pactRust": Object {"ffi": String("0.4.15")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2024-02-09T16:06:24.876512Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact after - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "a.b-service-i" }, provider: Provider { name: "a.b-provider" }, interactions: [], metadata: {"pactRust": Object {"ffi": String("0.4.15")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2024-02-09T16:06:24.876541Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact - ref = 1, keys = [1]
2024-02-09T16:06:24.876547Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact before - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "a.b-service-i" }, provider: Provider { name: "a.b-provider" }, interactions: [], metadata: {"pactRust": Object {"ffi": String("0.4.15")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2024-02-09T16:06:24.876554Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact after - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "a.b-service-i" }, provider: Provider { name: "a.b-provider" }, interactions: [], metadata: {"pact-js": Object {"version": String("12.2.0")}, "pactRust": Object {"ffi": String("0.4.15")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2024-02-09T16:06:24.876570Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact - ref = 1, keys = [1]
2024-02-09T16:06:24.876573Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact before - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "a.b-service-i" }, provider: Provider { name: "a.b-provider" }, interactions: [], metadata: {"pact-js": Object {"version": String("12.2.0")}, "pactRust": Object {"ffi": String("0.4.15")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
2024-02-09T16:06:24.876587Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_pact after - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "a.b-service-i" }, provider: Provider { name: "a.b-provider" }, interactions: [AsynchronousMessage { id: None, key: None, description: "", provider_states: [], contents: MessageContents { contents: Missing, metadata: {}, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }, comments: {}, pending: false, plugin_config: {}, interaction_markup: InteractionMarkup { markup: "", markup_type: "" }, transport: None }], metadata: {"pact-js": Object {"version": String("12.2.0")}, "pactRust": Object {"ffi": String("0.4.15")}}, plugin_data: [] }, mock_server_started: false, specification_version: V3 } }
# node -v
v16.20.2
# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

@YOU54F YOU54F closed this as completed Feb 9, 2024
@mefellows
Copy link
Member

Thanks Yousaf!

@teixeira-fernando
Copy link

teixeira-fernando commented Feb 28, 2024

I faced the same issue when trying to run a test with node version 20.11.1 and "@pact-foundation/pact": "12.1.3".

@YOU54F Would also be possible to have a solution for node versions 20+?

image

@YOU54F
Copy link
Member

YOU54F commented Feb 28, 2024

which distro are you running?

its tested against node 20 in this repo and its consuming repo pact-js

@teixeira-fernando
Copy link

teixeira-fernando commented Feb 28, 2024

It is the distro alpine (node:20.11.1-alpine).

This is the docker image: https://hub.docker.com/layers/library/node/20.11.1-alpine/images/sha256-f4c96a28c0b2d8981664e03f461c2677152cd9a756012ffa8e2c6727427c2bda?context=explore

I also tested the image 20.11.1 which does not use alpine, and it works fine. So, it seems that the problem is specifically for the alpine distros.

@YOU54F
Copy link
Member

YOU54F commented Feb 28, 2024 via email

@YOU54F
Copy link
Member

YOU54F commented Feb 28, 2024

look for the open rfc issue for alpine in this repo

@teixeira-fernando
Copy link

Thanks for the info. It was only later that I realized that this was a specific alpine problem. Looking forward to this coming Alpine support 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting feedback Awaiting Feedback from OP bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

5 participants