Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running AsyncApiModule.setup logs "Warning: Invalid hook call." and kills the process #551

Open
JohnICB opened this issue Feb 2, 2024 · 4 comments

Comments

@JohnICB
Copy link

JohnICB commented Feb 2, 2024

Describe the bug
Running AsyncApiModule.setup causes React error to appear in logs and stops the process.

Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

To Reproduce
Steps to reproduce the behavior:

  1. run npm i --save nestjs-asyncapi
  2. main.ts
    const app = await NestFactory.create(AppModule);

    const asyncApiServer: AsyncServerObject = {
        url: `ws://localhost:${port}`,
        protocol: 'socket.io',
        protocolVersion: '4',
        description:
            'Allows you to connect using the websocket protocol to our Socket.io server.',
        variables: {
            port: {
                description: 'Secure connection (TLS) is available through port 443.',
                default: '443',
            },
        },
        bindings: {},
    };

    const asyncApiOptions = new AsyncApiDocumentBuilder()
        .setTitle('Feline')
        .setDescription('Feline server description here')
        .setVersion('1.0')
        .setDefaultContentType('application/json')
        .build();
        
    await AsyncApiModule.setup('/async-api', app, AsyncApiModule.createDocument(app, asyncApiOptions));
    
    // ...
  1. See error in logs and the process exists

Expected behavior
The error to not appear in the logs and to start the dashboard.

Environment

    "@nestjs/axios": "^3.0.1",
    "@nestjs/cache-manager": "^2.2.0",
    "@nestjs/common": "^10.3.1",
    "@nestjs/config": "^3.1.1",
    "@nestjs/core": "^10.3.1",
    "@nestjs/event-emitter": "^2.0.3",
    "@nestjs/jwt": "^10.2.0",
    "@nestjs/mapped-types": "^2.0.4",
    "@nestjs/microservices": "^10.3.1",
    "@nestjs/passport": "^10.0.3",
    "@nestjs/platform-express": "^10.3.1",
    "@nestjs/platform-socket.io": "^10.3.1",
    "@nestjs/schedule": "^4.0.0",
    "@nestjs/swagger": "^7.2.0",
    "@nestjs/terminus": "^10.2.1",
    "@nestjs/websockets": "^10.3.1",
    ...
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.1",
    "express": "^4.18.2",
    ...
    "nestjs-asyncapi": "^1.2.2",

Node v20.10.0
TS: 4.7.2 Edit: Upgraded to 5.3.3, same result
Docker version 24.0.7, build afdd53b

For Tooling issues:

  • Platform: Mac with ARM Architecture

Others:

  • It's part of a monorepo using nx
  • If I remove the await (and let the promise run in the background) the log appears but it does not kill the application
  • It's the same when running locally and when running inside docker

Edit: using an AppModule empty (no modules imported) raises the same issue
I thought it was from the models, some are more complicated. I guess this rules it out
Edit: Upgraded tsc version

Copy link

github-actions bot commented Feb 2, 2024

Hello! Thank you for filing an issue.

If this is a bug report, please include relevant logs to help us debug the problem.

@flamewow
Copy link
Owner

flamewow commented Feb 2, 2024

Hey @JohnICB , thanks for reporting an issue.

Can you please move your setup into a min reproduction repo? I've quickly tried in an empty project and with latest nest version and can't reproduce your issue

@JohnICB
Copy link
Author

JohnICB commented Feb 5, 2024

Hey!
The issue probably is the fact that I have multiple dependencies to react and other libraries that has a dependency to react (such as tanstack query and tanstack router) that are of different versions
Must be the mix of 18.2.0 and 17.0.2 versions of react that don't play nicely.
Removing all other dependencies fixes the issue, even though async-api has dependencies to both versions of react, it somehow does not want to work with my other dependencies
image
^ this is working now
Installing it while having all these dependencies does not work anymore:
image
I'll try to setup a repo when I have the time to make it more easily to reproduce, but I think the issue is with the react-generator-sdk since it was the only dependency to react 17.0.2 at that time

@danyalutsevich
Copy link

danyalutsevich commented Feb 28, 2024

I had the same problem
I had a monorepo with react app and nestjs app (i used npm workspaces for monorepo)
I removed nestjs app from the monorepo and at this point it have separate node_modules and the async-api started to work

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

No branches or pull requests

3 participants