Hi Guys, I was following the below guide: <https:/...
# pact-broker
a
Hi Guys, I was following the below guide: https://github.com/pact-foundation/pact-workshop-js/tree/step11#step-11---using-a-pact-broker But got stuck in npm run pact:publish step.
Copy code
~/Contract-Testing-POC/pact-consumer:~ $ npm run pact:publish

> pact-consumer@1.0.0 pact:publish
> pact-broker publish ./pacts --consumer-app-version='1.0.0' --auto-detect-version-properties --broker-base-url=<http://localhost:8000> --broker-username pact_workshop --broker-password pact_workshop

node:internal/modules/cjs/loader:988
  throw err;
  ^

Error: Cannot find module '../src/pact-standalone'
Require stack:
- /Users/ankitjain/Contract-Testing-POC/pact-consumer/node_modules/.bin/pact-broker
    at Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
    at Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1051:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/Users/ankitjain/Contract-Testing-POC/pact-consumer/node_modules/.bin/pact-broker:7:43)
    at Module._compile (node:internal/modules/cjs/loader:1149:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1203:10)
    at Module.load (node:internal/modules/cjs/loader:1027:32)
    at Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/ankitjain/Contract-Testing-POC/pact-consumer/node_modules/.bin/pact-broker'
  ]
}
Node.js v18.10.0
y
can you show the output of
consumer/node_modules/.bin
there should be a
pact-broker
stub
Copy code
./node_modules/.bin/pact-broker
If it is there it probably hasn't downloaded the standalone binaries, are you on a corp proxy by chance? Were there any errors in the console when running your npm install command? Some other ways you can get at the CLI tool 👍 https://github.com/pact-foundation/pact_broker-client#installation
m
looks like something hasn’t installed properly
a
There is pact-broker inside .bin folder, but as you can see, pact-broker file requires pact-standalone module which is not present. In fact whole src folder is not present.
y
it pulls them down as a post install script, there will probably errors in your npm install log showing they can't be installed. This is from the old pact-node readme, I can't seem to find it in the pact-js-core https://www.npmjs.com/package/@pact-foundation/pact-node#pact-download-location
a
Sure @Yousaf Nabi (pactflow.io), will try specifying download location. When I am trying installing the cli, it looks like it is not supported in Mac M1 OS:
More logs
y
I run on an m1 mac and it's grand, that message in your terminal output is because it wasn't build on an arm platform, as we don't have build runners for them, they will work but take a performance hit
that is running, you can call the pact-broker command, but will need to mount your volume so the container has access to your pacts, and any env vars. instructions in the pact cli readme https://hub.docker.com/r/pactfoundation/pact-cli you can also install as a ruby gem
Best place I currently have it documented is here for the different ways is here https://docs.pactflow.io/docs/bi-directional-contract-testing/contracts/oas#installation I need to pull this onto the docs.pact.io site too
a
Thanks @Yousaf Nabi (pactflow.io), trying out your suggestions 🙂
Hi @Yousaf Nabi (pactflow.io) its a bad day for me i guess, Tried both methods, the cli is not available. Can you please tell what am i doing wrong
y
if you are trying to run the docker image, you pass your command in via docker run
Copy code
docker run --rm \
 -w ${PWD} \
 -v ${PWD}:${PWD} \
 -e PACT_BROKER_BASE_URL \
 -e PACT_BROKER_USERNAME \
 -e PACT_BROKER_PASSWORD \
  pactfoundation/pact-cli:latest \
  publish \
  ${PWD}/example/pacts \
  --consumer-app-version fake-git-sha-for-demo-$(date +%s) \
  --tag-with-git-branch
it won't make it available on your command line. To do that you need to install the gem, or download the standalone.
a
In the second screenshot, i tried the standalone method above.
y
it ran the pactflow command because it has downloaded and extracted the standalone to
./pact/bin/
so
./pact/bin/pact-broker
will work
its not automagically available on your system path, you would need to set that if required
a
Broker is running on 8000 port on localhost (via docker-compose up), same i have provided in broker base url variable, why it is showing this error.
y
Your docker cli run via docker run cannot talk to the host machine, so you need to set —network=host https://github.com/YOU54F/path-to-pact-nirvana/blob/45550fa9ddb2c56bfa9b5d09c9193d06f99a9ec8/Step_04_PublishYourFirstPactLocally/Makefile#L14 If you are running on a Mac or windows machine, the broker endpoint will be different https://github.com/YOU54F/path-to-pact-nirvana/blob/45550fa9ddb2c56bfa9b5d09c9193d06f99a9ec8/Step_04_PublishYourFirstPactLocally/Makefile#L37