Struggling to load js files to invoke getStaticPaths() for sitemap generation
Unanswered
Masai Lion posted this in #help-forum
Masai LionOP
I have a site using the pages directory that's completely SSR. I've written a file, /pages/sitemap.xml.js, that recursively goes throught the /pages directory and builds out the sitemap. My problem is that I have a few directories with [slug].js and in order to have a complete sitemap I need to invoke getStaticPaths() on them. I haven't been able to successfully load these files to call the function.
My approach is something like:
The filePath string is legit - in a terminal I can read the file using the filepath I generate in code - but for some reason in the Next environment I keep getting
Is there some kind of mechanism that prevents me from loading files off the filesystem? Am I doing something wrong here?
My approach is something like:
const filePath = path.join(process.cwd(), dir, file); //i.e. /Work/project/pages/exhibitions/[slug].js
const module = require(filePath);
if (module.getStaticPaths && typeof module.getStaticPaths === 'function') {
const staticPaths = await module.getStaticPaths();
.. process the paths ..
}The filePath string is legit - in a terminal I can read the file using the filepath I generate in code - but for some reason in the Next environment I keep getting
- error Error: Cannot find module '/Work/project/pages/exhibitions/[slug].js' Is there some kind of mechanism that prevents me from loading files off the filesystem? Am I doing something wrong here?