amqp-node / amqplib

AMQP 0-9-1 library and client for Node.JS

Home Page:https://amqp-node.github.io/amqplib/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Module not found: Can't resolve 'querystring'

benyaminl opened this issue · comments

Hello, I'm trying to use this client on nextjs, but I got error Module not found: Can't resolve 'querystring',

I'm using node 20 and nextjs 14

Error
⨯ ./node_modules/amqplib/lib/connect.js:10:0
Module not found: Can't resolve 'querystring'

image

I do check that Node 20 has querystring https://nodejs.org/docs/latest-v20.x/api/querystring.html

But why I got this error, it's what make me confused.

if is there any pointer regarding this, I would be thankful.

Ah... the problem is the lib/querystring.js isn't initiated on edge runtime (https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation#importing-runtime-specific-code)

vercel/next.js#50198

:/

So I need to manually use the import() and doing by this way..

export async function register()
{
    if (process.env.NEXT_RUNTIME === 'nodejs') {
        await import("./lib/rabbitmq").then(async (d) => {
            await d.PubSub();
        });
    }
}

@benyaminl glad you got it sorted and thank you for posting the solution