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

🐛 Bug Report: Framework - cant import NovuModule from '@novu/framework/dist/servers/nest'; #6769

Closed
2 tasks done
yunluo1024 opened this issue Oct 24, 2024 · 4 comments
Closed
2 tasks done

Comments

@yunluo1024
Copy link

📜 Description

I am trying to integrate NovuModule into my existing NestJS application, found that Novu released NestJS feature on 10/10/2024, followed the instructions to integrate NovuModule, but cant import NovuModule from "@novu/framework/nest".

👟 Reproduction steps

Followed the instructions from https://docs.novu.co/quickstart/nestjs, tried to import NovuModule from "@novu/framework/nest", seems Novu did not export NovuModule properly, below are npm dependencies.

 "@novu/framework": "^2.3.0",
   "xero-node": "^5.1.0",
    "zod": "^3.23.8",
   "zod-to-json-schema": "^3.23.5"

Cannot find module '@novu/framework/nest' or its corresponding type declarations.
There are types at '/Users/xx/SourceCode/api/node_modules/@novu/framework/dist/servers/nest.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.ts(2307)

👍 Expected behavior

should be able use nest NovuModule

👎 Actual Behavior with Screenshots

Screenshot 2024-10-25 at 9 22 31 AM

Novu version

Novu framework 2.3.0

npm version

10.8.2

node version

20.17.0

📃 Provide any additional context for the Bug.

No response

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find a similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to submit PR?

None

@paulwer
Copy link
Contributor

paulwer commented Oct 25, 2024

we had the same error, this is due to you probably using commonjs modules.
You can use a nestjs middleware with require as a workaround for now or wait until the next release is published.

import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';
import { serve } from '@novu/framework/dist/servers/express';
import workflows from './workflows/index';

@Injectable()
export class NovuMiddleware implements NestMiddleware {
    use(req: Request, res: Response, next: NextFunction) {
        // FIX: implement NovuModule when cjs is supported: 
        // Using require instead of import syntax, because novu export is not commonjs
        require("@novu/framework/express").serve({
            workflows: workflows.map(w => w.workflow),
        } as Parameters<typeof serve>['0'])(req, res, next)
    }
}

@yunluo1024
Copy link
Author

@paulwer thanks a lot for your info, will have a try.

@rifont rifont changed the title 🐛 Bug Report: cant import NovuModule from '@novu/framework/dist/servers/nest'; 🐛 Bug Report: Framework - cant import NovuModule from '@novu/framework/dist/servers/nest'; Nov 13, 2024
@rifont
Copy link
Collaborator

rifont commented Nov 13, 2024

hey @yunluo1024 , we have just released @novu/framework@2.4.0 with both ESM+CJS bundled into build artifacts 🎉

You will be able to remove the @ts-ignore on the import now.

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

No branches or pull requests

3 participants