This is the error message that keeps on appearing when I click a link.
Asked
Active
Viewed 312 times
-1

juliomalves
- 42,130
- 20
- 150
- 146

Scott Pessoa
- 9
- 2
-
Please use code snippets, do not use images for code. – juliomalves Nov 27 '21 at 14:50
3 Answers
1
The Error come from a change in bundleMDX parameters in their last version.
The correct way of using it should be
const source = fs.readFileSync(
path.join(process.cwd(), 'posts', `${slug}.mdx`),
'utf8'
);
const { code, frontmatter } = await bundleMDX({ source: source , ...});

DharmanBot
- 1,066
- 2
- 6
- 10

SuperAmdine
- 11
- 2
0
This error indicates that you are trying to import a module on client-side but that module is for nodejs environment. you may try mdx-bundler/client
as suggested here https://www.alaycock.co.uk/2021/03/mdx-bundler
The other way if moving all the parts to an api and call that api with one of these getServerSideProps
, getStaticProps
or inside of a useEffect
The link that I provided will solve your problems

oakar
- 1,187
- 2
- 7
- 21
-
From what OP posted, it looks like the error is happening on the server inside `getStaticProps`. – juliomalves Nov 27 '21 at 14:56
0
Building off of SuperAmdine's answer, you can edit getSourceOfFile
to be:
export const getSourceOfFile = (fileName) => {
return fs.readFileSync(path.join(POSTS_PATH, fileName), 'utf8');
};
Notice the addition of 'utf8'
.
and then
const {code, frontmatter} = await bundleMDX( {
source: source,
cwd: POSTS_PATH,
});
(I'm following the same blog tutorial and this got it working for me)

Ashbury
- 2,160
- 3
- 27
- 52