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

"cannot load such file" error in pact-node-verifier on Windows #237

Closed
thombergs opened this issue Oct 27, 2018 · 13 comments
Closed

"cannot load such file" error in pact-node-verifier on Windows #237

thombergs opened this issue Oct 27, 2018 · 13 comments

Comments

@thombergs
Copy link
Contributor

thombergs commented Oct 27, 2018

I'm trying to set up provider verification for a node express server.

This is the script I'm using to start the verification:

const { Verifier } = require('@pact-foundation/pact');
const packageJson = require('../package.json');

let opts = {
    providerBaseUrl: 'http://localhost:3000',
    provider: 'hero-provider',
    pactBrokerUrl: '...',
    pactBrokerUsername: process.env.PACT_USERNAME,
    pactBrokerPassword: process.env.PACT_PASSWORD,
    publishVerificationResult: true,
    providerVersion: packageJson.version,
    timeout: 5000
};

new Verifier().verifyProvider(opts).then(function () {
    console.log("verified");
});

Once verifyProvider() is called, I get some output that Pact is connecting to my Pact Broker and then I get this error:

...\node_modules\@pact-foundation\pact-node\standalone\install.js:263
    throw new Error(chalk.red("Unhandled Promise Rejection: " + e));
    ^

Error: Unhandled Promise Rejection: Error: C:/daten/workspaces/code-examples2/pact/pact-node-provider/node_modules/@pact-foundation/pact-node/standalone/win32-1.61.1/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.20.0/lib/pact/provider_verifier/app.rb:3:in `require': cannot load such file -- pact/provider_verifier/provider_states/remove_provider_states_header_middleware (LoadError)

The cause for this error is that the Ruby implementation of the pact-provider-verifier in my node_modules folder cannot load the file pact/provider_verifier/provider_states/remove_provider_states_header_middleware in a require declaration (app.rb line 3).

However, I checked the file and it exists.

Any clues about this behavior?

@mefellows
Copy link
Member

The first problem relates to an as-yet-undocumented issue relating to pact-node swallowing all promises (i.e. where the stack trace seems to originate, is actually not true).

My guess is you're running into file length issues (C:/daten/workspaces/code-examples2/pact/pact-node-provider/node_modules/@pact-foundation/pact-node/standalone/win32-1.61.1/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.20.0/lib/pact/provider_verifier/provider_states/remove_provider_states_header_middleware.rb is > 255 characters (see pact-foundation/pact-js-core#100 and pact-foundation/pact-js-core#101)

See if you can flatten the tree and if you still run into issues then we'll have to dig further.

There is also a way you can update the registry to allow longer path lengths it seems.

@thombergs
Copy link
Contributor Author

Yes, that was it, thanks.

The Windows registry hack hasn't worked for me, though, so I had to move the project to a shallower path.

@mefellows
Copy link
Member

:(

I'm really sorry, but also, Windows ¯_(ツ)_/¯

@thombergs
Copy link
Contributor Author

yeah, people keep telling me that... ;)

@yaroslavdraha
Copy link

I had the same issue on macOS Catalina, the shallower path has helped me! Thanks @mefellows

@mefellows
Copy link
Member

I had the same issue on macOS Catalina, the shallower path has helped me! Thanks @mefellows

What! That doesn't sound right to me, and may be a symptom of another problem. But, ... glad it worked :P

@AlexisLapeze
Copy link

I have the same issue and the Windows registery hack does not work for me ...

@mefellows
Copy link
Member

Try the v3 beta branch of Pact JS

@TimothyJones
Copy link
Contributor

What does ‘npm ls @pact-foundation/pact-node’ give you?

@AlexisLapeze
Copy link

What does ‘npm ls @pact-foundation/pact-node’ give you?

-- @pact-foundation/pact@9.14.0 -- @pact-foundation/pact-node@10.11.1

@TimothyJones
Copy link
Contributor

@AlexisLapeze: It's probably still path length. It looks like the registry edit suggested in the readme may not work depending on your version of windows. There is some discussion here: https://superuser.com/questions/1119883/windows-10-enable-ntfs-long-paths-policy-option-missing

If that doesn't work, try moving to a shallower path

Also, sometimes the binary fails to download during npm install- there's an error output when this happens, but it is sometimes ignored or doesn't get noticed. If this is the case, you can fix it by deleting node_modules/@pact-foundation/pact-node (or just node_modules) and rerunning npm install. My guess is this would be what happened in the macos case reported by @opium-draga , but I can't be certain.

@lulubobst
Copy link

Just ran into this May 13, 2022!

@TimothyJones
Copy link
Contributor

The issue is with the version of Ruby that is used by the pact core- which, on windows, does not handle long paths correctly. The next version of Pact uses a different core, which isn't using Ruby, and won't have this problem.

You may have some success with the beta release of pact-js - one of the maintainers may tell you what state it's in (I'm not up to date, as I'm not a pact maintainer any more)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants