triggerdotdev / trigger.dev

Trigger.dev is the open source background jobs platform.
https://trigger.dev/changelog
Apache License 2.0
9.4k stars 591 forks source link

bug: TypeError: (0 , import_react.cache) is not a function #1406

Open mattquestions opened 1 month ago

mattquestions commented 1 month ago

Provide environment information

System: OS: Linux 5.15 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish) CPU: (32) x64 AMD Ryzen 9 7950X 16-Core Processor Memory: 84.82 GB / 93.87 GB Container: Yes Shell: 5.1.16 - /bin/bash Binaries: Node: 21.2.0 - ~/.nvm/versions/node/v21.2.0/bin/node Yarn: 1.22.21 - ~/.nvm/versions/node/v21.2.0/bin/yarn npm: 10.2.3 - ~/.nvm/versions/node/v21.2.0/bin/npm pnpm: 8.10.5 - ~/.nvm/versions/node/v21.2.0/bin/pnpm Watchman: 2023.12.04.00 - /home/linuxbrew/.linuxbrew/bin/watchman

Describe the bug

I'm new to Trigger.dev, while trying to define the following task

`import { task } from "@trigger.dev/sdk/v3"; import { callReplicate } from '@/app/actions/replicate'; import { supabaseAdmin } from "@/lib/supabase/admin";

export const processImageTask = task({ id: "process-image-task", run: async (payload: { jobId: string }, { ctx }) => { // Fetch the job details from Supabase const { data: job, error: jobError } = await supabaseAdmin .from('jobs') .select('*') .eq('id', payload.jobId) .single();

  console.log(`trigger/process-image.ts job: ${JSON.stringify(job)}`);

  if (jobError || !job) {
    throw new Error('Job not found or failed to fetch job details.');
  }

  // Update job status to 'processing'
  await supabaseAdmin
    .from('jobs')
    .update({ status: 'processing' })
    .eq('id', payload.jobId);

  // Call the Replicate API to process the image
  const { data: result, error } = await callReplicate({
    type: "image-text-extractor",
    input: {
      image: job.image_url,
    },
  });   

  console.log(`trigger/process-image.ts result: ${JSON.stringify(result)}`);

  if (error) {
    throw new Error(`Image processing failed: ${error}`);
  }

  // Return the extracted text as the output of the task
  return { result };
},
onSuccess: async (payload, output, { ctx }) => {
  // Update job status to 'complete' and save the result
  await supabaseAdmin
    .from('jobs')
    .update({
      status: 'complete',
      result: JSON.stringify(output.result),
      updated_at: new Date().toISOString(),
    })
    .eq('id', payload.jobId);
},
onFailure: async (payload, error, { ctx }) => {
  // Update job status to 'failed'
  await supabaseAdmin
    .from('jobs')
    .update({
      status: 'failed',
      updated_at: new Date().toISOString(),
    })
    .eq('id', payload.jobId);
},

});`

I receive the following error

■ Error: Could not import trigger/process-image.ts │ │ TypeError: (0 , import_react.cache) is not a function │ at file:///home/user/project/lib/supabase/admin.ts:25:32 │ at ModuleJob.run (node:internal/modules/esm/module_job:218:25) │ at ModuleLoader.import (node:internal/modules/esm/loader:329:24) │ at tryImport (file:///home/user/.pnpm-store/v3/tmp/dlx-36225/node_modules/.pnpm/trigger.dev@3.0.12/node_modules/trigger.dev/src/indexing/registerTasks.ts:54:20) │ at registerTasks (file:///home/user/.pnpm-store/v3/tmp/dlx-36225/node_modules/.pnpm/trigger.dev@3.0.12/node_modules/trigger.dev/src/indexing/registerTasks.ts:8:29) │ at bootstrap (file:///home/user/.pnpm-store/v3/tmp/dlx-36225/node_modules/.pnpm/trigger.dev@3.0.12/node_modules/trigger.dev/src/entryPoints/dev-index-worker.ts:88:24) │ at file:///home/user/.pnpm-store/v3/tmp/dlx-36225/node_modules/.pnpm/trigger.dev@3.0.12/node_modules/trigger.dev/src/entryPoints/dev-index-worker.ts:98:49

In file:///home/user/project/lib/supabase/admin.ts, I have

import {cache} from "react";

Why is this happening?

Reproduction repo

I don't know how to provide Stackblitz/CodeSandbox, but this should be(?) easy to advice on.

To reproduce

Use import {cache} from "react"; in task definition.

Additional information

No response

ericallam commented 1 month ago

Which version of react are you using? If you are on React 18.x, unfortunately I don't think there's anything that can be done as that cache import is only available to experimental or canary releases of React (see here). If you are using Next.js you will be on one of those releases, which is why this works. One thing you could try is adding the react-server import condition in your trigger.config.ts file:

https://trigger.dev/docs/config/config-file#conditions