1

When I generate a nodejs-server with swagger 3.0.1 in the online tool https://editor.swagger.io/ and try to npm start the project I always get the following error:

enter image description here

Error: Cannot find module './middleware/swagger.router'

Alex
  • 119
  • 1
  • 10

2 Answers2

4

Short-term fix: you can get it to run until the maintainer of oas3-tools and Smartbear (for this server generator) fixes their respective parts.

PROBLEM A: oas3-tools build script isn't copying the 'middleware' over to the 'dist' directory.

To fix this:

  1. Start your generated server (this will run npm install and create the dist folder in node_modules/oas3-tools)
  2. Go into ./node_modules/oas3-tools and manually copy the missing src/middleware to the dist folder.
  3. Now that you have a middleware folder in your dist folder, run the following typescript compile command against it: tsc dist/middleware/

PROBLEM B:

The next issue is a typo on the path to the swagger document is incorrect.

To fix this:

  1. In the index.js file of your generated server, change the string 'api/openapi.yaml' to 'api/swagger.yaml'

POSSIBLE EXTRA PROBLEM:

You may need to manually transpile your .ts files. Please see @Alex's comment below if you also run into this (i.e. error TS6053: File 'dist/middleware/.ts' not found. Found 1 error)


Paulito.Bandito
  • 136
  • 2
  • 6
  • Just a note. Its also not picking up the port defined in the yaml file, so that will also need manually changing in the index.js – Gruffputs Jan 11 '20 at 13:26
  • Great catch! That would have been today's task to catch that. – Paulito.Bandito Jan 12 '20 at 14:31
  • hey @Paulito.Bandito, I followed the steps but the 3rd step is not working for me. I tried the command `tsc dist/middleware/` but I get the following error: ```error TS6053: File 'dist/middleware/.ts' not found. Found 1 error.``` – Alex Jan 15 '20 at 09:35
  • 1
    I finally had to tsc every file one by one and it worked, idk why it wasn't letting me transpile the whole folder :S – Alex Jan 15 '20 at 14:22
  • Hi Alex, glad it worked out for you! Sry, didn't get a chance to respond until now. – Paulito.Bandito Jan 17 '20 at 21:17
  • I have the same problem as @Alex. Could you please update your answer? I think this is an important note – Ri1a Oct 19 '20 at 12:45
0

The latest version of oas3-tools is 2.1.2 is screwed up. Use 2.0.2 for now.

oas3-tools : "2.0.2"
Nishant Shah
  • 2,022
  • 22
  • 20