nestjs / swagger

OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas:
https://nestjs.com
MIT License
1.68k stars 464 forks source link

New swagger plugin errors with nest monorepo #409

Closed gulaandrij closed 4 years ago

gulaandrij commented 4 years ago

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

nest start fails with new swagger plugin image

Expected behavior

app started

Minimal reproduction of the problem with instructions

https://github.com/gulaandrij/nest-monorepo-swagger steps:

yarn install
nest start

What is the motivation / use case for changing the behavior?

Environment


[System Information]
OS Version     : Linux 5.3
NodeJS Version : v13.1.0
YARN Version    : 1.19.2

[Nest Information]
platform-express version : 6.7.2
swagger version          : 4.0.2
common version           : 6.7.2
core version             : 6.7.2
kamilmysliwiec commented 4 years ago

Fixed in 4.0.3. Thanks for reporting!

danhooper commented 4 years ago

I'm still seeing this even on 4.03. I've forked the above repo with 4.0.3 and still see the issue:

https://github.com/danhooper/nest-monorepo-swagger

npm i
nest build
Starting type checking service...
Using 1 worker with 2048MB memory limit
/Users/hoopedc1/git/nest-monorepo-swagger/node_modules/typescript/lib/typescript.js:95861
                throw e;
                ^

TypeError: Cannot read property 'text' of undefined
    at IdentifierObject.TokenOrIdentifierObject.getText (/Users/hoopedc1/git/nest-monorepo-swagger/node_modules/typescript/lib/typescript.js:130308:31)
    at Object.getDecoratorName (/Users/hoopedc1/git/nest-monorepo-swagger/node_modules/@nestjs/swagger/dist/plugin/utils/ast-utils.js:88:65)
    at find.item (/Users/hoopedc1/git/nest-monorepo-swagger/node_modules/@nestjs/swagger/dist/plugin/utils/plugin-utils.js:8:89)
    at Array.find (<anonymous>)
    at Object.getDecoratorOrUndefinedByNames (/Users/hoopedc1/git/nest-monorepo-swagger/node_modules/@nestjs/swagger/dist/plugin/utils/plugin-utils.js:8:49)
    at ControllerClassVisitor.getStatusCodeIdentifier (/Users/hoopedc1/git/nest-monorepo-swagger/node_modules/@nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:65:50)
    at ControllerClassVisitor.createStatusPropertyAssignment (/Users/hoopedc1/git/nest-monorepo-swagger/node_modules/@nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:60:33)
    at ControllerClassVisitor.createDecoratorObjectLiteralExpr (/Users/hoopedc1/git/nest-monorepo-swagger/node_modules/@nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:35:18)
    at ControllerClassVisitor.addDecoratorToNode (/Users/hoopedc1/git/nest-monorepo-swagger/node_modules/@nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:27:22)
    at visitNode (/Users/hoopedc1/git/nest-monorepo-swagger/node_modules/@nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:16:29)
gulaandrij commented 4 years ago

still the same situation image

gulaandrij commented 4 years ago

ping @kamilmysliwiec

kamilmysliwiec commented 4 years ago

My mistake. Please update once again @gulaandrij @danhooper. 4.0.4 should be fine

gulaandrij commented 4 years ago

@kamilmysliwiec I have added DTO and receive the same error. Repo updated

danhooper commented 4 years ago

4.0.4 seems to fix it for my use case. Thanks!

danhooper commented 4 years ago

Actually I spoke to soon. Once I enable the DTO option I started getting the same error as well.

gulaandrij commented 4 years ago

@kamilmysliwiec 4.0.6 still the same

kamilmysliwiec commented 4 years ago

Thanks for the quick feedback! Please, test with 4.0.7 :)

gulaandrij commented 4 years ago

@kamilmysliwiec test repo now working fine. But my main project still failing with this error image I'm trying to reproduce it on test repo now

gulaandrij commented 4 years ago

@kamilmysliwiec I found an issue. Looks like it fails when dto is in lib and I use it in my main app. Repo updated

gulaandrij commented 4 years ago

also, could you reopen this while it still failing?

kamilmysliwiec commented 4 years ago

Sure thing. @gulaandrij thanks for your commitment. I've just pushed another fix that should solve your issue.

gulaandrij commented 4 years ago

tnx, it fix first start but got an error in watch mode. Steps to reproduce:

1. nest start --watch
2. add decorator @ApiResponse({status: 200}) in apps/swagger/src/app.controller.ts to trigger rebuild

repo updated

gulaandrij commented 4 years ago

image

kamilmysliwiec commented 4 years ago

Thanks for the investigation, it takes forever 😄 Please, update to the latest version and let me know if you are still encountering this issue

gulaandrij commented 4 years ago

tnx, errors have gone

zbeyens commented 4 years ago

@kamilmysliwiec The same bug happens when using yarn workspaces (monorepo). I don't have a public reproduction but the structure is similar to this https://github.com/AMGAVentures/poc-monorepo-starter

yarn workspaces enables us to use a single node_modules located at the root, but my nest app is at packages/api.

By copy/pasting node_modules/@nestjs/swagger folder to the nest app folder packages/api/node_modules, it works again. Basically the bug seems to happen when node_modules is not in the same folder than the nest app folder.

pethersonmoreno commented 4 years ago

the error "cannot read property 'kind' of undefined" is present yet.

pethersonmoreno commented 4 years ago

I've just open a new Issue about it:

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.