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:
Error: Cannot find module './middleware/swagger.router'
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:
dist
folder in node_modules/oas3-tools
)./node_modules/oas3-tools
and manually copy the missing src/middleware
to the dist
folder.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:
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
)