ErikWittern / openapi-snippet

Generates code snippets for given Swagger / Open API documents
MIT License
115 stars 66 forks source link

unable to build #92

Open nitinmcsam opened 2 years ago

nitinmcsam commented 2 years ago

openapi-snippet@0.14.0 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. (/home/mcsam/Desktop/test/openapi-snippet/node_modules/read-only-stream/index.js:28:44) at Labeled.emit (node:events:527:28) at Labeled. (/home/mcsam/Desktop/test/openapi-snippet/node_modules/stream-splicer/index.js:130:18) at Labeled.emit (node:events:527:28) at Deps. (/home/mcsam/Desktop/test/openapi-snippet/node_modules/stream-splicer/index.js:130:18) at Deps.emit (node:events:527:28) at DuplexWrapper. (/home/mcsam/Desktop/test/openapi-snippet/node_modules/module-deps/index.js:414:22)

nitinmcsam commented 2 years ago

after build command

lebiscuithd commented 1 year ago

Same issue here

jdeniau commented 1 year ago

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 ?

michaelgwelch commented 1 year ago

I can take a look

michaelgwelch commented 1 year ago

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.

michaelgwelch commented 1 year ago

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).

michaelgwelch commented 1 year ago

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.

jdeniau commented 1 year ago

Thanks for looking at it.

My node version is 14.18.0 for the record and the null coalesce opérator does work

image

michaelgwelch commented 1 year ago

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.

jdeniau commented 1 year ago

image

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.

jsau- commented 1 year ago

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!

zak905 commented 9 months ago

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