open-api icon indicating copy to clipboard operation
open-api copied to clipboard

Sample code for express-openapi is giving TypeError: url_1.URL is not a function

Open ashishjain3456 opened this issue 6 years ago • 2 comments

Hi,

I am trying to run https://github.com/kogosoftwarellc/open-api/tree/master/packages/express-openapi#getting-started code but it is giving below error: `/node_modules/openapi-framework/dist/src/BasePath.js:10 var serverUrl = url_1.URL(server.url, 'http://localhost'); ^

TypeError: url_1.URL is not a function at new BasePath (/node_modules/openapi-framework/src/BasePath.ts:10:19) at new OpenAPIFramework (node_modules/openapi-framework/index.ts:141:11) at initialize (/node_modules/express-openapi/index.ts:80:21) at Object. (/index.js:16:1) at Module._compile (module.js:570:32) at loader (/node_modules/babel-register/lib/node.js:144:5) at Object.require.extensions.(anonymous function) [as .js] (/node_modules/babel-register/lib/node.js:154:7) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Function.Module.runMain (module.js:604:10) at Object. (/node_modules/babel-cli/lib/_babel-node.js:154:22) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) [nodemon] app crashed - waiting for file`

When I further investigated inside node_modules/openapi-framework/dist/src/BasePath.js , I found that the url module really doesn't have any URL function, so if I change var serverUrl = new url_1.URL(server.url, 'http://localhost');

to

var serverUrl = new url_1.Url(server.url, 'http://localhost'); // Notice url_1.Url

it works Let me know if you need further assistance to replicate the issue

Thanks

ashishjain3456 avatar May 05 '19 19:05 ashishjain3456

@ashishjain3456 please open a PR to correct the code in the README.

jsdevel avatar May 06 '19 16:05 jsdevel

There's a mismatch in the path API. We are using Node v6.16.0 in production, but it doesn't support the new path API. I have to apply this diff before packaging everything up.

--- ./node_modules/openapi-framework/dist/src/BasePath.js    2019-04-03 11:31:43.000000000 -0500
+++ /node_modules/openapi-framework/dist/src/BasePath.js       2019-04-03 16:52:54.122511865 -0500
@@ -7,7 +7,7 @@
         this.path = '';
         // break the url into parts
         // baseUrl param added to make the parsing of relative paths go well
-        var serverUrl = new url_1.URL(server.url, 'http://localhost');
+        var serverUrl = url_1.parse(`http://localhost${server.url}`);
         var urlPath = decodeURI(serverUrl.pathname).replace(/\/$/, '');
         if (/{\w+}/.test(urlPath)) {
             // has variable that we need to check out
@@ -26,4 +26,4 @@
     return BasePath;
 }());
 exports["default"] = BasePath;
-//# sourceMappingURL=BasePath.js.map
\ No newline at end of file
+//# sourceMappingURL=BasePath.js.map

fuddlesworth avatar May 13 '19 15:05 fuddlesworth