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

Windows 11: Exception during run: TypeError: Cannot read properties of undefined (reading 'pactffiInitWithLogLevel') #608

Open
4 of 5 tasks
vlevkoniuk opened this issue Mar 3, 2025 · 6 comments
Labels
awaiting feedback Awaiting Feedback from OP bug Indicates an unexpected problem or unintended behavior triage This issue is yet to be triaged by a maintainer

Comments

@vlevkoniuk
Copy link

vlevkoniuk commented Mar 3, 2025

Software versions

Please provide at least OS and version of pact-js

  • OS: Windows 11 Pro (latest)
  • Pact Node version: "@pact-foundation/pact": "^14.0.0",
  • Node Version: 22

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

Windows 11 should support pact tests like the Windows 10 does

Actual behaviour

Exception during run: TypeError: Cannot read properties of undefined (reading 'pactffiInitWithLogLevel')

Steps to reproduce

On a Windows 11 machine install @pact-foundation/pact": "^14.0.0", and write some test that has

const provider = new PactV3({
        consumer: 'consumer-v3',
        provider: 'provider-v3'
    });

The execution will fail before mocha (test framework begin to lunch test)

> cross-env LOG_LEVEL=trace CI=true mocha

Debugger attached.
Debugger attached.
[21:34:49.288] DEBUG (5052): pact-core@16.0.0: We detected your platform as: 

 - win32-x64

 Exception during run: TypeError: Cannot read properties of undefined (reading 'pactffiInitWithLogLevel')
    at getFfiLib (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\node_modules\@pact-foundation\pact-core\src\ffi\index.ts:188:14)
    at makeConsumerPact (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\node_modules\@pact-foundation\pact-core\src\consumer\index.ts:71:24)
    at PactV3.PactV3.setup (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\node_modules\@pact-foundation\src\v3\pact.ts:250:33)
    at new PactV3 (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\node_modules\@pact-foundation\src\v3\pact.ts:49:10)
    at Suite.<anonymous> (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\tests\image-service-pact-v3.spec.ts:9:22)
    at Object.create (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\node_modules\mocha\lib\interfaces\common.js:148:19)
    at context.describe.context.context (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\node_modules\mocha\lib\interfaces\bdd.js:42:27)
    at <anonymous> (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\tests\image-service-pact-v3.spec.ts:6:1)
    at Object.<anonymous> (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\tests\image-service-pact-v3.spec.ts:87:2)
    at Module._compile (node:internal/modules/cjs/loader:1554:14)
    at Object.transformer (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\node_modules\tsx\dist\register-DCnOAxY2.cjs:2:1186)
    at Module.load (node:internal/modules/cjs/loader:1289:32)
    at Function._load (node:internal/modules/cjs/loader:1108:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)
    at cjsLoader (node:internal/modules/esm/translators:262:5)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:196:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:271:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:578:26)
    at async formattedImport (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\node_modules\mocha\lib\nodejs\esm-utils.js:9:14)
    at async exports.requireOrImport (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\node_modules\mocha\lib\nodejs\esm-utils.js:42:28)
    at async exports.loadFilesAsync (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\node_modules\mocha\lib\nodejs\esm-utils.js:100:20)
    at async singleRun (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\node_modules\mocha\lib\cli\run-helpers.js:162:3)
    at async exports.handler (C:\Users\vlevkoniuk\sources\QA-AUTOMATION-TYPESCRIPT-1\lesson13-contract-testing\node_modules\mocha\lib\cli\run.js:375:5)
@vlevkoniuk vlevkoniuk added the bug Indicates an unexpected problem or unintended behavior label Mar 3, 2025
@YOU54F
Copy link
Member

YOU54F commented Mar 3, 2025

Pact-JS does work on windows 11 machines ( I have two that I use at home for developing both pact-js-core and testing), so there is some other issue here

@mefellows mefellows added the triage This issue is yet to be triaged by a maintainer label Mar 3, 2025
@mefellows
Copy link
Member

Any chance you could please create a repro? Perhaps forking https://github.com/mefellows/pact-js-repro-template (it might be a little out of date now, but should be easy to update) and sharing your forked project that demonstrates the issue?

@mefellows mefellows added the awaiting feedback Awaiting Feedback from OP label Mar 4, 2025
@vlevkoniuk
Copy link
Author

vlevkoniuk commented Mar 4, 2025

OK, so I found the problem

After you said that you have it working on your Windows OSs I started to think what is the difference between my Windows 10 where everything working fine and Windows 11 envs. The difference is that on Windows 10 a long time ago I was using Node.js installed from installer before switching to NVM, on windows 11 I am using just nvm.

The problem is that I used nvm to install Node.js. As a result, I have not installed dependencies that are automatically installed after nodejs installation using an installer downloaded from the official site.

So probably dependencies are like python visualstudio2022-workload-vctools as it is said in node-gyp instructions, but node-gyp is required for pact version lower then 11?

So maybe it would be a good time to update installation instructions for those who are using NVM or other node version manager tools? I mean what dependencies, because nodejs post-install script downloads and installs a lot of staff

PS
using WSL installed nodejs by nvm and it is working fine there
So the issue is only using nvm on Windows

@YOU54F
Copy link
Member

YOU54F commented Mar 4, 2025

re: https://github.com/pact-foundation/pact-js/blob/master/docs/troubleshooting.md#installation-failing-missing-python-c-or-build-tools

So probably dependencies are like python visualstudio2022-workload-vctools as it is said in node-gyp instructions, but node-gyp is required for pact version lower then 11?

v10-v11 require node-gyp for the build process.

v12 + prebuilds dependencies so removes this requirement

v9 and below never had this requirement in the first place

I use a combo of nvm / nvs on macos, nvm on windows with no issues.

I previously had nvm 1.1.0 with node 16 installed on my laptop directly from the gh releases executable

https://github.com/coreybutler/nvm-windows

however I have re-tried with latest nvm installed via choco and node 22.14.0 and all good. (windows 11 pro 23H2)

using this repo

https://github.com/pact-foundation/pact-workshop-js/blob/22d6e16619a5b3db1dc4d0dacb7b1333493aed97/consumer/package.json#L17

updated pact to v14 and pact-cli to 16.0.5

npm install / npm test - ✅

@vlevkoniuk
Copy link
Author

are you sure that you Windows machine had no nodejs installation before?

I am using clean windows with just VS code installed and nvm with node v22 and the problem happened
After installing nodejs and it post-install scripts and then removing nodejs - everything works OK

@YOU54F
Copy link
Member

YOU54F commented Mar 4, 2025

I tried again in a clean Win11 VM (ARM64 on MacOS M1)

Had the same issue as yourself with nvm and nvs due to them not bundling the additional support packages.

You are correct that the official nodejs installer for windows supports the additional options

Image

Following the link shown takes us to

https://github.com/nodejs/node-gyp?tab=readme-ov-file#on-windows

Where we can see the instruction (to be run in a powershell session with admin priviledges)

choco install python visualstudio2022-workload-vctools -y

Now I will note that this didn't install cleanly

WARNING: Errors/warnings from the Visual Studio Installer log file C:\Users\yousaf.nabi\AppData\Local\Temp\chocolatey\dd_installer_20250304162921.log:
WARNING: [1b70:000a][2025-03-04T16:29:31] Warning: Didn't find any channel feed.
WARNING: [1b70:0017][2025-03-04T16:29:38] Warning: Didn't find any channel feed.
WARNING: [1b70:000a][2025-03-04T16:29:38] Warning: The operation was canceled.
WARNING: [1b70:000a][2025-03-04T16:29:38] Warning: Didn't find any channel feed.
WARNING: [1b70:0020][2025-03-04T16:29:38] Warning: Failed to get the HttpWebResponse while invoking a HEAD request against https://aka.ms/vs/channels:System.OperationCanceledException: The operation was canceled.
WARNING: [1b70:001f][2025-03-04T16:29:38] Warning: Failed to download channels file from https://aka.ms/vs/channels: A task was canceled.
WARNING: [1b70:0022][2025-03-04T16:29:38] Warning: Failed to get the HttpWebResponse while invoking a HEAD request against https://aka.ms/vs/installer/latest/feed:System.OperationCanceledException: The operation was canceled.
WARNING: [1b70:0023][2025-03-04T16:29:38] Warning: Failed to update the latest installer feed A task was canceled.
WARNING: [1b70:0023][2025-03-04T16:29:38] Warning: Didn't find any channel feed.
WARNING: [1b70:0003][2025-03-04T16:29:38] Warning: Didn't find any channel feed.
WARNING: [1b70:0005][2025-03-04T16:29:38] Warning: Didn't find any channel feed.
WARNING: [1b70:001e][2025-03-04T16:29:56] Error 0x80131500: Failed to deserialize instance state: An instance of the product cannot be loaded. You can uninstall the product, or visit https://aka.ms/vs/cleanup for more help with this issue.
WARNING: [1b70:001e][2025-03-04T16:29:56] Error 0x80004003: Failed to read instance dbcaff20
WARNING: [1b70:0005][2025-03-04T16:29:56] Warning: Didn't find any channel feed.
WARNING: [1b70:001e][2025-03-04T16:29:56] Warning: Shutting down the application with exit code 1618
WARNING: [1b70:001e][2025-03-04T16:29:56] Warning: Pre-check verification failed with warning(s) :  AnotherInstallationRunning,ArmMachineCheck.
WARNING: [1b70:0001][2025-03-04T16:29:56] Warning: Didn't find any channel feed.
WARNING: [1b70:0001][2025-03-04T16:29:57] Warning: Didn't find any channel feed.
WARNING: Errors/warnings from the Visual Studio Installer log file C:\Users\yousaf.nabi\AppData\Local\Temp\chocolatey\dd_installer_elevated_20250304162939.log:
WARNING: [06f4:0005][2025-03-04T16:29:45] Warning: Cannot set layout uri to null.
WARNING: [06f4:0005][2025-03-04T16:29:51] Warning: Scheduling without hotload: No hotloadable VSIX packages were present in the plan
WARNING: [06f4:0005][2025-03-04T16:29:52] Warning: Pre-check verification: Your machine is busy installing a program other than Visual Studio.
WARNING: [06f4:0005][2025-03-04T16:29:52] Warning: Pre-check verification: Installing Visual Studio on an ARM-powered device is not supported. If you continue, Visual Studio might be slow or unusable. For the best experience with ARM-based devices, we recommend remote targeting. For more information, please review our documentation for [Visual Studio on ARM-powered devices](https://aka.ms/vs/arm).
WARNING: [06f4:0005][2025-03-04T16:29:56] Error: Pre-check verification failed with warning(s) :  AnotherInstallationRunning,ArmMachineCheck.
WARNING: [06f4:0005][2025-03-04T16:29:56] Error 0x652: Pre-check verification failed with warning(s) :  AnotherInstallationRunning,ArmMachineCheck.
WARNING: [06f4:0005][2025-03-04T16:29:56] Error 0x652: Engine threw an exception that is not being rethrown: Pre-check verification failed with warning(s) :  AnotherInstallationRunning,ArmMachineCheck.
WARNING: [06f4:0001][2025-03-04T16:29:56] Warning: Didn't find any channel feed.
WARNING: [06f4:0001][2025-03-04T16:29:56] Warning: Didn't find any channel feed.
WARNING: Content of Visual Studio Installer error log file C:\Users\yousaf.nabi\AppData\Local\Temp\chocolatey\dd_setup_20250304162945_errors.log:
WARNING: [06f4:0005][2025-03-04T16:29:56] Pre-check verification failed with warning(s) :  AnotherInstallationRunning,ArmMachineCheck.
WARNING: [06f4:0005][2025-03-04T16:29:56] Error 0x652: Pre-check verification failed with warning(s) :  AnotherInstallationRunning,ArmMachineCheck.
WARNING:    at Microsoft.VisualStudio.Setup.PrecheckManager.RunPrechecks(PrecheckParameters precheckParameters, VariableCollection properties)
WARNING:    at Microsoft.VisualStudio.Setup.Engine.RunPrecheck(String destination, Product product, ExecuteAction action, IWindowsRestartManager rmService, ITelemetryOperation installOperation, InstallOperation install)
WARNING:    at Microsoft.VisualStudio.Setup.Engine.Install(Product product, String destination, CancellationToken token)

Here are the installed packages

Installed:
 - chocolatey-compatibility.extension v1.0.0
 - chocolatey-core.extension v1.4.0
 - chocolatey-dotnetfx.extension v1.0.1
 - chocolatey-visualstudio.extension v1.11.1
 - chocolatey-windowsupdate.extension v1.0.5
 - dotnetfx v4.8.0.20220524
 - KB2919355 v1.0.20160915
 - KB2919442 v1.0.20160915
 - KB2999226 v1.0.20181019
 - KB3033929 v1.0.5
 - KB3035131 v1.0.3
 - python v3.13.1
 - python3 v3.13.1
 - python313 v3.13.1
 - vcredist140 v14.42.34438.20250221
 - vcredist2015 v14.0.24215.20170201
 - visualstudio-installer v2.0.3

However I was able to successfully execute the pact tests after this

PS C:\Users\yousaf.nabi\dev\pact-workshop-js-master\pact-workshop-js-master\consumer> npm test

> consumer@0.1.0 test
> cross-env CI=true react-scripts test

 PASS  src/api.spec.js
2025-03-04T16:31:15.270533Z  WARN ThreadId(02) pact_models::pact: Note: Existing pact is an older specification version (V2), and will be upgraded
 PASS  src/api.pact.spec.js
2025-03-04T16:31:15.378593Z  WARN ThreadId(02) pact_models::pact: Note: Existing pact is an older specification version (V2), and will be upgraded
2025-03-04T16:31:15.410057Z  WARN ThreadId(02) pact_models::pact: Note: Existing pact is an older specification version (V2), and will be upgraded
2025-03-04T16:31:15.447694Z  WARN ThreadId(02) pact_models::pact: Note: Existing pact is an older specification version (V2), and will be upgraded
2025-03-04T16:31:15.468417Z  WARN ThreadId(02) pact_models::pact: Note: Existing pact is an older specification version (V2), and will be upgraded

Test Suites: 2 passed, 2 total
Tests:       8 passed, 8 total
Snapshots:   0 total
Time:        4.637 s
Ran all test suites.
PS C:\Users\yousaf.nabi\dev\pact-workshop-js-master\pact-workshop-js-master\consumer>

Where previously I would see the same as your initial issue.

Therefore I think its prudent to update the documents to state that windows users using the official nodejs package will need to tick that option, and other uses with nvs/nvm/volta or a direct install of node-js will require these support packages noted in https://github.com/nodejs/node-gyp?tab=readme-ov-file#on-windows, on a bare install.

Thanks for raising and helping reduce the size of the haystack!

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 triage This issue is yet to be triaged by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants