-
-
Notifications
You must be signed in to change notification settings - Fork 604
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: TypeError: (0 , import_react.cache) is not a function #1406
Comments
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 |
Hi there! I understand you're running into an issue with the React cache function in your Trigger.dev task. Let me help you resolve this. The error you're seeing is because the React
export default {
// ... other config
conditions: {
// Add react-server condition to support React Server Components
import: ["react-server"]
}
}
// Instead of React's cache
let cachedClient: SupabaseClient | null = null;
export const supabaseAdmin = (() => {
if (cachedClient) return cachedClient;
cachedClient = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.SUPABASE_SERVICE_ROLE_KEY!
);
return cachedClient;
})(); This solution uses a simple module-level singleton pattern which achieves similar caching behavior without depending on React's experimental features. The second approach is more reliable for Trigger.dev tasks since they run in a Node.js environment where React server components features aren't typically needed. Let me know if you need any clarification or run into any other issues! References:
|
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();
});`
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/[email protected]/node_modules/trigger.dev/src/indexing/registerTasks.ts:54:20) │ at registerTasks (file:///home/user/.pnpm-store/v3/tmp/dlx-36225/node_modules/.pnpm/[email protected]/node_modules/trigger.dev/src/indexing/registerTasks.ts:8:29) │ at bootstrap (file:///home/user/.pnpm-store/v3/tmp/dlx-36225/node_modules/.pnpm/[email protected]/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/[email protected]/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
The text was updated successfully, but these errors were encountered: