Prism does not start mock locally
SamJust opened this issue · 1 comments
SamJust commented
When I try to start mock server locally, I get an error. No matter what src for OpenAPI spec source I use.
Context
It does not start mock server
Current Behavior
The command crashes
Throws an error
[3:34:15 PM] › [CLI] ✖ fatal Error downloading https://raw.githack.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml
The "emitter" argument must be an instance of EventEmitter or EventTarget. Received an instance of AbortSignal
prism mock <document>
Start a mock server with the given document file
Positionals:
document Path to a document file. Can be both a file or a fetchable resource
on the web. [string] [required]
Options:
--version Show version number [boolean]
--help Show help [boolean]
-p, --port Port that Prism will run on.
[number] [required] [default: 4010]
-h, --host Host that Prism will listen to.
[string] [required] [default: "127.0.0.1"]
--cors Enables CORS headers. [boolean] [default: true]
-m, --multiprocess Forks the http server from the CLI for faster log
processing. [boolean] [default: false]
--errors Specifies whether request/response violations marked as
errors will produce an error response
[boolean] [required] [default: false]
-v, --verboseLevel Turns on verbose logging.
[required] [choices: "trace", "debug", "info", "warn", "error", "fatal",
"silent"] [default: "info"]
-d, --dynamic Dynamically generate examples. [boolean] [default: false]
{
stack: 'ResolverError: Error downloading https://raw.githack.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml \n' +
'The "emitter" argument must be an instance of EventEmitter or EventTarget. Received an instance of AbortSignal\n' +
' at download (/Users/viktorbezrdonyi/.nvm/versions/node/v18.15.0/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/json-schema-ref-parser/lib/resolvers/http.js:175:11)\n' +
' at processTicksAndRejections (node:internal/process/task_queues:95:5)',
code: 'ERESOLVER',
message: 'Error downloading https://raw.githack.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml \n' +
'The "emitter" argument must be an instance of EventEmitter or EventTarget. Received an instance of AbortSignal',
source: 'https://raw.githack.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml',
path: null,
toJSON: [Function: toJSON],
ioErrorCode: 'ERR_INVALID_ARG_TYPE',
name: 'ResolverError',
toString: [Function: toString]
}
Expected Behavior
The mock server starts
Steps to Reproduce
- $ npm i -g @stoplight/prism-cli
- $ prism mock https://raw.githack.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml
Environment
- Version used: 5.0.1
- Environment name and version: Node v18.15.0
- Operating System and version: MacOS: 13.2.1 (22D68)
- Link to your environment/workspace/project: It's a single CLI call.
EdVinyard commented
As you said, Prism is broken running under Node.js 18.15.x.
% sw_vers -productVersion # Mac OS version
13.4
% nvm install 18.15.0
Downloading and installing node v18.15.0...
Downloading https://nodejs.org/dist/v18.15.0/node-v18.15.0-darwin-x64.tar.xz...
###################################################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v18.15.0 (npm v9.5.0)
% npm install --global @stoplight/prism-cli
...
% prism --version
5.0.1
% prism mock https://raw.githack.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml
[9:38:32 AM] › [CLI] … awaiting Starting Prism…
[9:38:32 AM] › [CLI] ✖ fatal Error downloading https://raw.githack.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml
The "emitter" argument must be an instance of EventEmitter or EventTarget. Received an instance of AbortSignal
...
However, the problem is fixed in 18.16.x.
% nvm use 18
Now using node v18.16.1 (npm v9.5.1)
% npm install --global @stoplight/prism-cli
npm WARN deprecated json-schema-ref-parser@6.1.0: Please switch to @apidevtools/json-schema-ref-parser
...
% prism --version
5.0.1
% prism mock https://raw.githack.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml
[9:34:14 AM] › [CLI] … awaiting Starting Prism…
[9:34:15 AM] › [CLI] ℹ info GET http://127.0.0.1:4010/pets
[9:34:15 AM] › [CLI] ℹ info POST http://127.0.0.1:4010/pets
[9:34:15 AM] › [CLI] ℹ info GET http://127.0.0.1:4010/pets/-2232339446628286500
[9:34:15 AM] › [CLI] ℹ info DELETE http://127.0.0.1:4010/pets/-8359716962358653000
[9:34:15 AM] › [CLI] ▶ start Prism is listening on http://127.0.0.1:4010
[9:34:27 AM] › [HTTP SERVER] get /pets ℹ info Request received
[9:34:27 AM] › [NEGOTIATOR] ℹ info Request contains an accept header: */*
[9:34:27 AM] › [VALIDATOR] ✔ success The request passed the validation rules. Looking for the best response
[9:34:27 AM] › [NEGOTIATOR] ✔ success Found a compatible content for */*
[9:34:27 AM] › [NEGOTIATOR] ✔ success Responding with the requested status code 200
[9:34:27 AM] › [NEGOTIATOR] ℹ info > Responding with "200"
It looks like the cause is an issue in Node.js's version of undici, as discussed here and fixed in 18.16.x. Although there is a workaround possible for 18.15 I don't think we'll incorporate that into Prism itself.
We recommend an upgrade to 18.16.x, and I'll update the documentation to include this caveat for Node.js 18.x in this PR.