-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Closed
Description
Bug report
When attempting to reference the local file system, I often use __dirname to ensure that I can use relative path names. However while using getStaticProps, __dirname is not resolving correctly.
Describe the bug
I expected __dirname to be the absolute path of the file in which getStaticProps is being executed, but instead it is incorrectly resolving as /.
To Reproduce
I am using this component in the pages directory under the name faq.js:
import React from 'react';
export default function FAQ ({ faq }) {
return (
<pre >
{ faq }
</pre>
)
}
export async function getStaticProps() {
const read = require('util').promisify(require('fs').readFile);
const path = require('path');
console.log(__dirname);
const faq = await read(path.join(__dirname, 'faq.md'), 'utf8');
return { faq };
};Expected behavior
I expect __dirname to be the relative path name of faq.js, but it instead is output as / in the console during next build. This is causing the file faq.md to not be read properly because it is not on the correct path.
System information
- OS: MacOS
- Version of Next.js:
9.3.0
digitaldesigndj, aweber1, lostfictions, ivanpetrushev, jim-y and 7 more
Metadata
Metadata
Assignees
Labels
No labels