Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Error: Cannot find module swagger_router #586

Open
TomlDev opened this issue May 20, 2019 · 23 comments
Open

Error: Cannot find module swagger_router #586

TomlDev opened this issue May 20, 2019 · 23 comments

Comments

@TomlDev
Copy link

TomlDev commented May 20, 2019

Hello, I just tried the npm tutorial "your swagger API in five steps", linux mint 19.04, nodejs 12.2.0, npm 6.9.0

$ npm install -g swagger
$ swagger project create hello-world     # create with express
$ cd hello-world
$ swagger project edit

After that I finish editing with CTRL+C and try to start the project:

$ swagger project start

I get the follow error:

/home/tom/tutorials/hello-world$ swagger project start
Starting: /home/tom/tutorials/hello-world/app.js...
  project started here: http://localhost:10010/
  project will restart on changes.
  to restart at any time, enter `rs`
Error initializing middleware
Error: Cannot find module '/home/tom/tutorials/hello-world/api/fittings/swagger_router'
Require stack:
- /home/tom/tutorials/hello-world/node_modules/bagpipes/lib/fittingTypes/user.js
- /home/tom/tutorials/hello-world/node_modules/bagpipes/lib/bagpipes.js
- /home/tom/tutorials/hello-world/node_modules/bagpipes/lib/index.js
- /home/tom/tutorials/hello-world/node_modules/swagger-node-runner/index.js
- /home/tom/tutorials/hello-world/node_modules/swagger-express-mw/lib/index.js
- /home/tom/tutorials/hello-world/app.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:610:15)
    at Function.Module._load (internal/modules/cjs/loader.js:526:27)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at createFitting (/home/tom/tutorials/hello-world/node_modules/bagpipes/lib/fittingTypes/user.js:18:20)
    at Bagpipes.newFitting (/home/tom/tutorials/hello-world/node_modules/bagpipes/lib/bagpipes.js:158:17)
    at Bagpipes.createFitting (/home/tom/tutorials/hello-world/node_modules/bagpipes/lib/bagpipes.js:147:22)
    at Bagpipes.createPipe (/home/tom/tutorials/hello-world/node_modules/bagpipes/lib/bagpipes.js:111:19)
    at Bagpipes.getPipe (/home/tom/tutorials/hello-world/node_modules/bagpipes/lib/bagpipes.js:50:38)
    at /home/tom/tutorials/hello-world/node_modules/bagpipes/lib/bagpipes.js:34:10
@pz2147
Copy link

pz2147 commented May 22, 2019

I know how to fixed this issue.

Copy some files
from project/node_modules/swagger-node-runner/fittings to project/api/fittings/swagger_router,
from project/node_modules/bagpipes/lib/fittings to project/api/fittings/swagger_router

Finally, start is OK.

I think I have make a wrong path with module.

@ranrao
Copy link

ranrao commented May 29, 2019

Is this the best approach to fix the issue? This seems like a new problem with Swagger. Please help with the right approach. Thanks.

@deventorum
Copy link

This is probably because you are running node v12.2.0! Try to downgrade your node to version 10, version 12 is not stable.

@racingfever
Copy link

I also had same problems. Tried the file copying from fittings-directory. This didn't work for me.
I downgraded node to 10.16.0 (and npm 6.9.0) and all was solved....

@binhapp
Copy link

binhapp commented Jul 10, 2019

@deventorum Node v10.16.0 is work for me. Thank you!

@crutlandTAG
Copy link

I have the exact same issue as the OP. Node v12 is becoming LTS in one month; I'd generally assume I should be able to follow the instructions in the README and have a working 'getting started' project. This doesn't appear to be the case at the moment.

@rajeshpudota
Copy link

I have the exact same issue too. I was trying to upgrade to node v12.

Error initializing middleware
Error: Cannot find module '/Users/nodejs/services/account/api/fittings/swagger_router'
Require stack:

  • /Users/nodejs/services/account/node_modules/bagpipes/lib/fittingTypes/user.js
  • /Users/nodejs/services/account/node_modules/bagpipes/lib/bagpipes.js
  • /Users/nodejs/services/account/node_modules/bagpipes/lib/index.js
  • /Users/nodejs/services/account/node_modules/swagger-node-runner/index.js
  • /Users/nodejs/services/account/node_modules/swagger-express-mw/lib/index.js
  • /Users/nodejs/services/account/node_modules/cm-util/app-start.js
  • /Users/nodejs/services/account/node_modules/cm-util/index.js
  • /Users/nodejs/services/account/app.js

@s-kalaus
Copy link

Problem is that in Node 12 Module Not Found error differs from Node 10. bagpipes relies on error message text. This can tepmorary be fixed in this file: node_modules/bagpipes/lib/fittingTypes/user.js file:
var split = err.message.split(path.sep);
should be
var split = err.message.split('\n')[0].split(path.sep);

@shiranyo
Copy link

Happens to me as well on node 12

@Ethns
Copy link

Ethns commented Nov 29, 2019

Same issue
env: node 12.13.1 npm 6.12.1

@gohmc
Copy link

gohmc commented Dec 1, 2019

Try this, tested on node version to date (12.13.1):

  1. Update your swagger-express-mw:

"swagger-express-mw": "^0.7.0"

  1. Add swagger_params_parser to swagger_controllers at config/default.yaml
    ...

pipe for all swagger-node controllers

swagger_controllers:
  - onError: json_error_handler
  - cors
  - swagger_params_parser
  ...
  1. Run npm install

  2. Run swagger project start

I wish swagger-node will receive more timely update.

@taitelman
Copy link

I also had to move to node 12 and since I felt this lib is no longer maintained nor supported I decided to shift to swagger-ui-express . the above solution could have saved me serveral hours of debugging.

@sonywibisono
Copy link

try to install swagger-router with command
$npm install --save swagger-router

it's work for me

@amrendraw3
Copy link

This is probably because you are running node v12.2.0! Try to downgrade your node to version 10, version 12 is not stable.

This worked for me as well, downgraded to v10.15.0.

@smeckman
Copy link

smeckman commented Apr 2, 2020

@gohmc - Thank you, your solution works splendidly with v12.16.1 and requires minimal configuration without touching the code.

@balain
Copy link

balain commented Nov 9, 2020

Try this, tested on node version to date (12.13.1):

1. Update your swagger-express-mw:

"swagger-express-mw": "^0.7.0"

1. Add swagger_params_parser to swagger_controllers at config/default.yaml
   ...

pipe for all swagger-node controllers

swagger_controllers:
  - onError: json_error_handler
  - cors
  - swagger_params_parser
  ...
1. Run npm install

2. Run swagger project start

I wish swagger-node will receive more timely update.

Thanks for the fix @gohmc.

Note: this fix also works for me with node v15.1.0

@cp99says
Copy link

Try this, tested on node version to date (12.13.1):

  1. Update your swagger-express-mw:

"swagger-express-mw": "^0.7.0"

  1. Add swagger_params_parser to swagger_controllers at config/default.yaml
    ...

pipe for all swagger-node controllers

swagger_controllers:
  - onError: json_error_handler
  - cors
  - swagger_params_parser
  ...
  1. Run npm install
  2. Run swagger project start

I wish swagger-node will receive more timely update.

I did the same but the issue wasnt resolved, its showing this error
`Error initializing middleware
Error: Cannot find module 'D:\swagggggger\hello\api\fittings\swagger_router'
Require stack:

  • D:\swagggggger\hello\node_modules\bagpipes\lib\fittingTypes\user.js
  • D:\swagggggger\hello\node_modules\bagpipes\lib\bagpipes.js
  • D:\swagggggger\hello\node_modules\bagpipes\lib\index.js
  • D:\swagggggger\hello\node_modules\swagger-node-runner\index.js
  • D:\swagggggger\hello\node_modules\swagger-express-mw\lib\index.js
  • D:\swagggggger\hello\app.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1080:15)
    at Function.Module._load (internal/modules/cjs/loader.js:923:27)
    at Module.require (internal/modules/cjs/loader.js:1140:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at createFitting (D:\swagggggger\hello\node_modules\bagpipes\lib\fittingTypes\user.js:18:20)
    at Bagpipes.newFitting (D:\swagggggger\hello\node_modules\bagpipes\lib\bagpipes.js:158:17)
    at Bagpipes.createFitting (D:\swagggggger\hello\node_modules\bagpipes\lib\bagpipes.js:147:22)
    at Bagpipes.createPipe (D:\swagggggger\hello\node_modules\bagpipes\lib\bagpipes.js:111:19)
    at Bagpipes.getPipe (D:\swagggggger\hello\node_modules\bagpipes\lib\bagpipes.js:50:38)
    at D:\swagggggger\hello\node_modules\bagpipes\lib\bagpipes.js:34:10`

how should I sort it out? @gohmc

@JonanOribe
Copy link

JonanOribe commented Jan 3, 2021

I solved the problem downgrading my Node version to 10.23.0

@adarshsingh6162
Copy link

adarshsingh6162 commented Nov 8, 2021

Try this, tested on node version to date (12.13.1):

  1. Update your swagger-express-mw:

"swagger-express-mw": "^0.7.0"

  1. Add swagger_params_parser to swagger_controllers at config/default.yaml
    ...

pipe for all swagger-node controllers

swagger_controllers:
  - onError: json_error_handler
  - cors
  - swagger_params_parser
  ...
  1. Run npm install
  2. Run swagger project start

I wish swagger-node will receive more timely update.

This fixes the error but routes are not working properly.
For eg. 1) - GET /path/{id}
2) - POST /path/xyz

while making call to POST /path/xyz, it's throwing error method POST is not defined for /path/{id}
It's treating xyz as some id

@SteversIO
Copy link

Wow this project is absolutely unmaintained. I experienced the same issue as all of the above.

Even the code that is auto-generated for the hello world controller is stale.

req.param('name') is the valid way to pull parameters from the request object now.

Now req.swagger.params.name.value

@sscots
Copy link

sscots commented Jan 31, 2022

I think I've figured out a way around this error with the following changes to the fittingsDir:

fittingsDirs: [ node_modules/swagger-node-runner/fittings ]

Then I had to remove this line under "swagger_controllers" to get it work, or else I get an error complaining about "onError" not being a fitting.

- onError: json_error_handler

I don't think, in my case, that I really need the json_error_handler. But tbh, I'm not 100% sure what it does. Does anyone know?

@mozhaev94
Copy link

  • onError: json_error_handler
    • cors
    • swagger_params_parser

Thank you! It`s works for me

@CiriloGaspar
Copy link

CiriloGaspar commented Jul 15, 2022

Try this, tested on node version to date (12.13.1):

  1. Update your swagger-express-mw:

"swagger-express-mw": "^0.7.0"

  1. Add swagger_params_parser to swagger_controllers at config/default.yaml
    ...

pipe for all swagger-node controllers

swagger_controllers:
  - onError: json_error_handler
  - cors
  - swagger_params_parser
  ...
  1. Run npm install
  2. Run swagger project start

I wish swagger-node will receive more timely update.

Thanks alot, it's works for me.

I had the same issue with env:

Node -v: 16.16.0

npm -v: 8.11.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests