is importing getStaticProps in a page component not supported?
#17826
Unanswered
stefanprobst
asked this question in
Help
Replies: 2 comments 5 replies
-
|
probably related: #16153 |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Could you instead create a helper and not export For example: import * as fs from 'fs';
import { join } from 'path';
export default function MyGspHelper() {
const { title } = JSON.parse(
fs.readFileSync(join(process.cwd(), 'metadata.json'))
);
return { title }
}import MyGspHelper from '../helpers/MyGspHelper';
export default function Screen(props) {
return <h1>{props.title}</h1>;
}
export async function getStaticProps() {
const props = MyGspHelper();
return { props };
}You can use this tool to see what gets eliminated: https://next-code-elimination.now.sh/ and in this case it should eliminate the imports from the |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
{{title}}
-
when not writing
getStaticPropsdirectly in a page component, but importing it from somewhere else, i see a "Module not found: Can't resolve 'fs'" error.is the following not supported? (or a limitation of the babel plugin)?
Beta Was this translation helpful? Give feedback.
All reactions