-
Notifications
You must be signed in to change notification settings - Fork 395
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
Error: Cannot find module '/.next/worker-script/node/index.js' when using server functions with zerox in Next.js #99
Comments
Hey @KitaharaMugiro. This problem might be outside of zerox. Zerox shouldn't rely on any worker-script functionality. Can you try logging what is in your next/worker-script directory?
|
Hi guys! this issue is happening to me too. I was also working with Nextjs Server actions, now I have switched to Current API:import { NextRequest, NextResponse } from "next/server";
import path from "path";
import fs from "fs/promises";
export async function POST(request: NextRequest) {
try {
const formData = await request.formData();
const file = formData.get("file") as File | null;
if (!file) {
return NextResponse.json({ error: "File is required!" }, { status: 400 });
}
// Create a temporary file path
const tempDir = process.cwd() + "/temp";
await fs.mkdir(tempDir, { recursive: true });
const tempFilePath = path.join(tempDir, `${Date.now()}-${file.name}`);
// Convert file to buffer and save
const bytes = await file.arrayBuffer();
const buffer = Buffer.from(bytes);
await fs.writeFile(tempFilePath, buffer);
try {
// Dynamically import zerox
const { zerox } = await import("zerox");
const { pages } = await zerox({
filePath: tempFilePath, // Use the uploaded file path
openaiAPIKey: process.env.OPENAI_KEY,
});
// Clean up the temporary file
await fs.unlink(tempFilePath);
return NextResponse.json({
pages,
pageCount: pages.length,
});
} catch (processingError) {
// cleanup
await fs.unlink(tempFilePath);
return NextResponse.json(
{
error: "Failed to process file",
details:
processingError instanceof Error
? processingError.message
: String(processingError),
},
{ status: 500 }
);
}
} catch (error) {
return NextResponse.json(
{
error: "Failed to upload file",
details: error instanceof Error ? error.message : String(error),
},
{ status: 500 }
);
}
}
export const config = {
api: {
bodyParser: false, // Disable default body parser
},
maxDuration: 300, // 5 minutes max execution time
}; Versions
Additionally If anyone can help, or has already worked with this, help out!! |
@tylermaran do you guys use zerox in nextjs? If so would it be possible to have an example repo of using it? |
Not sure if this is the exact issue @tylermaran @alexander-densley . `/** @type {import('next').NextConfig} */ module.exports = nextConfig ` |
Bug Report
Description
An error occurs when running a server function in a Next.js application using
zerox
. The issue is related to a missing module:/Users/mugiro/ai-chatbot/.next/worker-script/node/index.js
.Reproduction
Use the following server-side code:
Run the application.
Observe the following error logs in the terminal:
Expected Behavior
The
processFile
function should process the uploaded file, extract text usingzerox
, and save the extracted text to a file without errors.Actual Behavior
The application crashes with the error:
Additional Context
The issue might be related to the
.next/worker-script
directory not being correctly generated or referenced. The error occurs consistently, even after clearing.next
and rebuilding the project.Steps Taken
.next
directory and rebuilt the project.The text was updated successfully, but these errors were encountered: