prism
prism copied to clipboard
mock fails with `TypeError: Cannot read properties of undefined (reading 'isMaster')`
Context
You cannot start mock
server command
Current Behavior
Running mock
command on the prim cli using either directly NodeJS source code or Dockerfile throws the following error:
TypeError: Cannot read properties of undefined (reading 'isMaster')
at createMultiProcessPrism (/usr/src/prism/packages/cli/dist/util/createServer.js:27:32)
at Object.runPrismAndSetupWatcher (/usr/src/prism/packages/cli/dist/util/runner.js:8:12)
at Object.handler (/usr/src/prism/packages/cli/dist/commands/mock.js:27:25)
at Object.runCommand (/usr/src/prism/node_modules/yargs/build/index.cjs:446:48)
at Object.parseArgs [as _parseArgs] (/usr/src/prism/node_modules/yargs/build/index.cjs:2697:57)
at Object.get [as argv] (/usr/src/prism/node_modules/yargs/build/index.cjs:2651:25)
at Object.<anonymous> (/usr/src/prism/packages/cli/dist/index.js:15:26)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
Expected Behavior
I would expect the command to work successfully
Possible Workaround/Solution
The problem seems to be that when compiling prism using yarn build
command, the output of the file packages/cli/dist/util/createServer.js
regarding the node:cluster
module seems to be wrong. The related lines are:
L7: const node_cluster_1 = require("node:cluster");
L27: if (node_cluster_1.default.isMaster) {
CAUSE
The default
attribute on node_cluster_1
is undefined leading to the TypeError
mentioned above. As far as I know .default
was never an attribute of the node cluster module. So I guess this is due to some compilation or types error of the module
Steps to Reproduce
-
yarn && yarn build
-
node . mock <api-spec-file>
Exactly the same with Dockerfile using latest stoplight/prism
image
Environment
- Version used: 4.latest as of today 15/9/2022
- Environment name and version (e.g. Chrome 39, node.js 5.4): NodeJS 16.17 and latest docker image
stoplight/prism:4
I have the same problem when I try to launch prism in a github workflow
middleware_1 | prism mock <document>
middleware_1 |
middleware_1 | Start a mock server with the given document file
middleware_1 |
middleware_1 | Positionals:
middleware_1 | document Path to a document file. Can be both a file or a fetchable resource on the web. [string] [required]
middleware_1 |
middleware_1 | Options:
middleware_1 | --version Show version number [boolean]
middleware_1 | --help Show help [boolean]
middleware_1 | -p, --port Port that Prism will run on. [number] [required] [default: 4010]
middleware_1 | -h, --host Host that Prism will listen to. [string] [required] [default: "127.0.0.1"]
middleware_1 | --cors Enables CORS headers. [boolean] [default: true]
middleware_1 | -m, --multiprocess Forks the http server from the CLI for faster log processing. [boolean] [default: true]
middleware_1 | --errors Specifies whether request/response violations marked as errors will produce an error response [boolean] [required] [default: false]
middleware_1 | -d, --dynamic Dynamically generate examples. [boolean] [default: false]
middleware_1 |
middleware_1 | TypeError: Cannot read properties of undefined (reading 'isMaster')
middleware_1 | at createMultiProcessPrism (/usr/src/prism/packages/cli/dist/util/createServer.js:27:32)
middleware_1 | at Object.runPrismAndSetupWatcher (/usr/src/prism/packages/cli/dist/util/runner.js:8:12)
middleware_1 | at Object.handler (/usr/src/prism/packages/cli/dist/commands/mock.js:27:25)
middleware_1 | at Object.runCommand (/usr/src/prism/node_modules/yargs/build/index.cjs:446:48)
middleware_1 | at Object.parseArgs [as _parseArgs] (/usr/src/prism/node_modules/yargs/build/index.cjs:2697:57)
middleware_1 | at Object.get [as argv] (/usr/src/prism/node_modules/yargs/build/index.cjs:2651:25)
middleware_1 | at Object.<anonymous> (/usr/src/prism/packages/cli/dist/index.js:15:26)
middleware_1 | at Module._compile (node:internal/modules/cjs/loader:1126:14)
middleware_1 | at Object.Module._extensions..js (node:internal/modules/cjs/loader:[118]
middleware_1 | at Module.load (node:internal/modules/cjs/loader:1004:32)
presse-front-e2e_middleware_1 exited with code 1
Prism is started with Docker-Compose :
version: '3.9'
services:
app:
image: presse-front
ports:
- 1312:3000
middleware:
image: stoplight/prism:4
command: 'mock -h 0.0.0.0 /tmp/api.oas3.yml'
volumes:
- ./middleware/api.oas3.yaml:/tmp/api.oas3.yaml:ro
But I don't encounter the problem in local :
➜ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy
➜ docker --version
Docker version 20.10.16, build aa7e414
➜ docker-compose --version
docker-compose version 1.27.4, build 40524192
Hey team! Please add your planning poker estimate with Zenhub @brendarearden @daniel-white @EdVinyard @fcasad
I was seeing this issue with the latest release of the stoplight/prism:4
Docker image (released 8 days ago). I pinned the image at stoplight/prism:4.10.3
and the issue went away.
I confirm that the problem disappears by using the image stoplight/prism:4.10.3
i can also confirm that i had the same issues when using prism:4
and prism:latest
, and the issue was fixed by pinning it to 4.10.3
. thanks @captaincoordinates & @alexisjanvier !
Hello all!
I have the reported issue with 4.10.4, but it is sporadic :(
I have read you use cluster.isMaster
but it is deprecated, can you use cluster.isPrimary
? I cannot prove it is the root cause, but the sporadic failing is not a production usage :(
rollback to 4.10.2 solves my problem thanks to @fcasad notes: https://github.com/stoplightio/prism/pull/2143
Hi everyone, Sorry you were affected by the regression in 4.10.4! It should be resolved in 4.10.5.