Skip to content

Critical dependency warning when running in Next.js #466

Open
@chrboe

Description

@chrboe

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions