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

Critical dependency warning when running in Next.js #466

Open
chrboe opened this issue May 15, 2024 · 3 comments
Open

Critical dependency warning when running in Next.js #466

chrboe opened this issue May 15, 2024 · 3 comments
Labels

Comments

@chrboe
Copy link

chrboe commented May 15, 2024

Summary

When including Graphile Worker in a Next.js project, dependency warnings are thrown.

Steps to reproduce

import {quickAddJob} from "graphile-worker";

export async function POST(req: Request) {
    const payload = req.text();
    const job = await quickAddJob(
        { connectionString: process.env.DATABASE_URL },
        "test-task",
        {payload},
    );
    console.log(`Job added: ${job.id}`);
    return new Response(null, {status: 200});
}

Expected results

The job gets enqueued.

Actual results

The job is enqueued, but this warning is shown in the console:

[22:10:45.274] WARN (next.js/1652545): ./node_modules/graphile-worker/node_modules/cosmiconfig/dist/loaders.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/graphile-worker/node_modules/cosmiconfig/dist/loaders.js
./node_modules/graphile-worker/node_modules/cosmiconfig/dist/index.js
./node_modules/graphile-worker/dist/config.js
./node_modules/graphile-worker/dist/preset.js
./node_modules/graphile-worker/dist/index.js
./src/app/api/test-worker/route.ts
    prefix: "warn"

Additional context

I tried modifying my Next.js config as suggested in #345:

config.module.rules.push(
            {
                test: [
                    path.resolve("node_modules/pg/lib/native"),
                    path.resolve("node_modules/import-fresh"),
                    path.resolve("node_modules/graphile-worker/dist/getTasks"),
                ],
                loader: "null-loader",
            },
        );

But that only partly solved the issue. There were more warnings displayed before changing the config, though.

Possible Solution

I suspect there is some way to exclude a certain module to make the warnings go away, but nothing I have tried has worked so far.

@benjie
Copy link
Member

benjie commented May 17, 2024

I think the solution for this would be to add "exports" to package.json and then export a subpath for WorkerUtils ("exports": {"./utils": {...}}) that does not need to contain any of the dynamic task loading logic. Further, we should make a stripped down WorkerUtils that doesn't know how to run migrations (since that also loads files). You'll still have issues bundling it since the pg library attempts to load pg-native, but this'll help.

Alternatively, just use the Next configuration to stub out all the problematic parts that you don't need.

@benjie
Copy link
Member

benjie commented May 17, 2024

Or you could just call graphile_worker.add_jobs() database function directly from your code and skip the worker utils to do so entirely.

@psugihara
Copy link

@chrboe you ever find a solution you like for this? I'm hitting the exact same problem trying to integrate graphile-worker with typescript tasks into a typescript-based next.js app.

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

No branches or pull requests

3 participants