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

Dynamic module promises in the exports array is broken #13733

Closed
2 of 15 tasks
micalevisk opened this issue Jun 30, 2024 · 6 comments · Fixed by #14114
Closed
2 of 15 tasks

Dynamic module promises in the exports array is broken #13733

micalevisk opened this issue Jun 30, 2024 · 6 comments · Fixed by #14114

Comments

@micalevisk
Copy link
Member

micalevisk commented Jun 30, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Since the commit be6d90a#diff-10d05a74883d097e0c5b94c8564bd68b26cfcc9c57b32e3e0c0024c9e91c3e88 (nestjs v6), the following is supposed to work but it doesn't:

const whenDynamicModule: Promise<DynamicModule> = Promise.resolve({
  module: class MyModule {},
})

@Module({
  imports: [whenDynamicModule],
  exports: [whenDynamicModule],
})
export class AppModule {}

it crashes with the following error:

Error: Nest cannot export a provider/module that is not a part of the currently processed module (Bar). Please verify whether the exported [object Promise] is available in this particular context.

Possible Solutions:
- Is [object Promise] part of the relevant providers/imports within Bar?

we can easily see that this is either a missing feature or a regression.

Minimum reproduction code

https://gitlab.com/micalevisk/nestjs-issue-13733

Steps to reproduce

git clone https://gitlab.com/micalevisk/nestjs-issue-13733
cd nestjs-issue-13733
npm ci
npm start
## se the error

Expected behavior

I tested it with nestjs v6, v7 (with a different error), v8, v9, v10 so I'm pretty sure that this was never supported besides what the type definition says.

I found that after testing the ConditionalModule feature with dynamic modules returning promises. I never saw anyone reporting this error before so I'd say that this is not common pattern at all.

I tried to fix this but due to the async nature I didn't managed to fix it easily.

So instead of starting supporting it now in v10, I'd rather prefer to drop the Promise<DynamicModule> type from exports in NestJS v11. Or just drop it now in v10 because it doesn't seem to be used anyway.

If anyone starting asking for such fix in <=v10, we could suggest them to use
exports: [YourDynamicModule] instead and tell them that this is not a feature but a wrong type definition.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

10.3.9

Packages versions

N/A

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@micalevisk micalevisk added the needs triage This issue has not been looked into label Jun 30, 2024
@Kelvin-ui-hub
Copy link

Hey, let me try and work on it

@micalevisk
Copy link
Member Author

@Kelvin-ui-hub go ahead. PRs are more than welcomed

@kelvin-go-get
Copy link

Okay thanks

@micalevisk
Copy link
Member Author

@kamilmysliwiec can we just drop this feature in the next major release as it never worked anyway?

@kamilmysliwiec
Copy link
Member

Sounds good @micalevisk. Would you like to create a PR for this?

@micalevisk micalevisk removed the needs triage This issue has not been looked into label Nov 7, 2024
@kamilmysliwiec
Copy link
Member

#14114

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

Successfully merging a pull request may close this issue.

4 participants