File System error
Unanswered
Brown bear posted this in #help-forum
Brown bearOP
const folders = await fs.readdir(courseLessonsFolder); <-- This is the error line. It works in dev, but not in production.
[Error: ENOENT: no such file or directory, scandir 'courses/single-variable-calculus/lessons/'] {
errno: -2,
code: 'ENOENT',
syscall: 'scandir',
path: 'courses/single-variable-calculus/lessons/'
}
[Error: ENOENT: no such file or directory, scandir 'courses/single-variable-calculus/lessons/'] {
errno: -2,
code: 'ENOENT',
syscall: 'scandir',
path: 'courses/single-variable-calculus/lessons/'
}
9 Replies
@Brown bear const folders = await fs.readdir(courseLessonsFolder); <-- This is the error line. It works in dev, but not in production.
[Error: ENOENT: no such file or directory, scandir 'courses/single-variable-calculus/lessons/'] {
errno: -2,
code: 'ENOENT',
syscall: 'scandir',
path: 'courses/single-variable-calculus/lessons/'
}
Brown bearOP
I've done the same line numerous times, and they all work in production, but for some reason, they don't work here?
Brown bearOP
export async function getCourseLessonsMetaData(course: string) {
const testPath = path.join(process.cwd(), "courses", course, "lessons");
const folders = await fs.readdir(testPath); // <---- This is 1000% the cause of the error. It works in dev, but not in production.
let courseLessonsMeta: CourseLessonMetaData[] = [];
for (const folder of folders) {
try {
const module = await import(
`/courses/${course}/lessons/${folder}/index.mdx`
);
const metadata = module.metadata;
metadata.slug = folder;
courseLessonsMeta.push(metadata);
} catch (error) {
// Handle the error here
console.error(`Error processing folder ${folder}:`, error);
}
}
courseLessonsMeta.sort((a, b) => (a.unitNumber < b.unitNumber ? -1 : 1));
return courseLessonsMeta;
}
const testPath = path.join(process.cwd(), "courses", course, "lessons");
const folders = await fs.readdir(testPath); // <---- This is 1000% the cause of the error. It works in dev, but not in production.
let courseLessonsMeta: CourseLessonMetaData[] = [];
for (const folder of folders) {
try {
const module = await import(
`/courses/${course}/lessons/${folder}/index.mdx`
);
const metadata = module.metadata;
metadata.slug = folder;
courseLessonsMeta.push(metadata);
} catch (error) {
// Handle the error here
console.error(`Error processing folder ${folder}:`, error);
}
}
courseLessonsMeta.sort((a, b) => (a.unitNumber < b.unitNumber ? -1 : 1));
return courseLessonsMeta;
}
Brown bearOP
Nope
it's a server component
Brown bearOP
No but I'll try it
Here's the thing, it works in dev but not in production
so I'm very doubtful use server will change anything