Is next-mdx broken in Next.js v8?
I'm trying to parse a .md file but it doesn't work no matter what I try.
component:
import glossary from '../markdown/glossary/glossary.md'
export default () => (
<div>{glossary}</div>
)
next.config.js
const withPlugins = require('next-compose-plugins')
const withCSS = require('@zeit/next-css')
const withMDX = require('@zeit/next-mdx')({
extension: /\.(md|mdx)$/
})
module.exports = withPlugins([
withMDX,
withCSS
], {
target: 'serverless'
})
And the error is
Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.
in div (at glossary.jsx:4)
in Unknown (created by App)
in Container (created by App)
in App
I even tried exporting like this
module.exports = withPlugins([
withMDX(),
withCSS()
], {
target: 'serverless'
})
and then a different error occurs
./markdown/glossary/glossary.md 1:0
Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
> # Reactive Manifesto Glossary
|
| * [Asynchronous](#Asynchronous)
Can someone tell me what exactly is the issue? Because I believe I'm extending the webpack config properly, just don't understand why it won't parse.
Ran into the same thing. This works:
{
target: 'serverless',
webpack(c) {
c.module.rules.push({
test: /\.mdx?$/,
use: ['babel-loader', '@mdx-js/loader']
})
return c
}
}
Same issue here, not solved 👎
Here is working on next.js v9.1 with:
next.config.js
const withPlugins = require('next-compose-plugins');
const withCSS = require('@zeit/next-css');
const withMDX = require('@next/mdx')({
extension: /\.(md|mdx)$/,
});
module.exports = withPlugins([
withMDX({
pageExtensions: ['js', 'jsx', 'mdx', 'md'],
}),
withCSS
]);
/* without 'withPlugins'
module.exports = withCSS(
withMDX({
pageExtensions: ['js', 'jsx', 'mdx', 'md'],
})
);
*/
- imported
.mdfile is a React Component .mdfiles must be imported from apagefile. It will not work from a children component (follow the same rules as getInitialProps)
pages/index.js
import Readme from '../doc/readme.md';
export default () => <Readme />;
~~@bySabi can we get some version info other than next? I am using all latest and this does not work. I copied your exact configuration~~
Module parse failed: Unexpected character '#' (2:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
~~In my case I have;~~
~~1. Created a page~~ ~~2. Imported a md file to that page~~
~~I am not trying to generate pages from mdx~~
~~Might also be worth noting that I tested with next@^9.1 and latest @next/mdx -- no difference in behaviour.~~
Scratch this -- It works perfectly. frekkin Mac space sneaked itself inside next.config.js´s filename.
Hey! We're deprecating this repository, next-mdx has been moved to https://npmjs.com/@next/mdx
@timneutkens Thanks. It could've been an issue with my code syntax itself, since I now see that I tried to import the markdown file like this
import glossary from '../markdown/glossary/glossary.md'
export default () => (
<div>{glossary}</div>
)
which is probably not the proper way to import the markdown file, but rather it should be imported like this
import Glossary from '../markdown/glossary/glossary.md'
// or
import glossary from '../markdown/glossary/glossary.md'
export default () => (
<Glossary />
// or
<div dangerouslySetInnerHTML={{ __html: glossary }} />
)
Although I remember trying a lot of different methods to import the markdown file without any success, but thanks for letting us know that the repository is now deprecated.