openapi-snippet
openapi-snippet copied to clipboard
unable to build
[email protected] build mkdir -p dist && browserify -g uglifyify ./index.js > ./dist/openapisnippet.min.js
SyntaxError: Unexpected token: operator (?) while parsing file: /home/mcsam/Desktop/test/openapi-snippet/openapi-to-har.js
at Z.get (/home/mcsam/Desktop/test/openapi-snippet/node_modules/terser/dist/bundle.min.js:1:463)
at Readable.errorExit (/home/mcsam/Desktop/test/openapi-snippet/node_modules/browserify/bin/cmd.js:79:27)
at Readable.emit (node:events:527:28)
at Labeled.
after build command
Same issue here
Same issue with webpack that wants a specific loader.
ERROR in ./node_modules/openapi-snippet/openapi-to-har.js 230:17
Module parse failed: Unexpected token (230:17)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|
| const objects = [];
> style = style ?? getDefaultStyleForLocation(location);
| explode = explode ?? getDefaultExplodeForStyle(style);
|
@ ./node_modules/openapi-snippet/index.js 11:21-51
@ ./docs/App.js
@ ./docs/index.js
Version ^0.13 does work, but 0.14.0 does not work. Maybe @michaelgwelch might know why ?
I can take a look
FYI, we use version 0.14.0 which has been working for us and which I believe was the first released version to include my changes.
Is this a minimum version of node issue? Perhaps I (and @ErikWittern ) used a newer version of node. Is the ?? operator not supported in your version of node?
If that's the issue, it's easily fixed by using || instead of ?? (I think).
Looks like ?? was added in node 14.5 per https://node.green/#ES2020-features--nullish-coalescing-operator-----
So perhaps this library needs to specify a minimum version of node, or rewrite that little bit to not use ?? operator.
Unfortunately, I think Erik is rather busy. I've submitted another issue and PR to fix it and haven't heard anything back. So while I can create a fix and make a PR, it's unlikely to be merged for some time.
Thanks for looking at it.
My node version is 14.18.0 for the record and the null coalesce opérator does work

Just wondering. Could you clone the repo, and npm install and npm run test? I'm going to test it locally using your version of node.
The only issue I find with v14.18.0 is that the replaceAll method on string isn't supported until v15.14 (https://node.green/#ES2021-features--String-prototype-replaceAll) but that's only used in the test file and isn't used in the library code itself.

According to MDN replaceAll has been introduced in node 15.
But the only reference is in a test file.
The webpack issues seems weird though as a loader is something that is determined by the file extension.
Looks like
??was added in node 14.5 per https://node.green/#ES2020-features--nullish-coalescing-operator-----So perhaps this library needs to specify a minimum version of node, or rewrite that little bit to not use
??operator.
I did open a PR to replace the ?? operators with checks compatible with lower versions of Node last July I think (see https://github.com/ErikWittern/openapi-snippet/pull/91).
If that's been superceded by anything you've done just let me know and I can close mine!
Hi @michaelgwelch, I am also encountring this issue. My node version is v14.17.1. I think that maybe providing a ready to use script for those who do not want or who cannot build the repo, can help. Many projects do it, including Swagger UI: https://github.com/swagger-api/swagger-ui/tree/master/dist