Comments (4)
My next js version is "next": "9.3.4"
. I will try once after downgrading the version. Will report back 👍 Thanks for your help.
from gatsby-mdx.
I tested styled components in a simple app - the mdx runtime (https://github.com/karolis-sh/gatsby-mdx/blob/master/demos/mdx-scoped-runtime-playground/src/App.js) handles it fine:
import React from 'react';
import MDX from 'mdx-scoped-runtime';
import { ThemeProvider } from 'styled-components';
import CoolQuote from './ui/CoolQuote';
const Layout = ({ children }) => (
<ThemeProvider theme={{ colors: { fourthLight: 'mediumseagreen' } }}>{children}</ThemeProvider>
);
const initialMdx = `import CoolQuote from "./ui/CoolQuote";
import Layout from "./Layout";
export default Layout
<CoolQuote>
<i>TEST</i>
</CoolQuote>
`;
export default class App extends React.Component {
state = { mdx: initialMdx };
render() {
const { mdx } = this.state;
return (
<div style={{ width: 500, margin: '40px auto' }}>
<textarea
style={{ width: '100%', height: 130 }}
value={mdx}
onChange={(e) => this.setState({ mdx: e.target.value })}
/>
<MDX
allowedImports={{
'./ui/CoolQuote': { ImportDefault: CoolQuote },
'./Layout': { ImportDefault: Layout },
}}
>
{mdx}
</MDX>
</div>
);
}
}
As the error states - it's hooks usage issues. I had some similar issues with gatsby and netlify-cms. You'll need to tweak nextjs webpack config.
from gatsby-mdx.
Hard luck, I changed my cms.js to match your solution, yet the same error happens.
my cms.js is as follows:
import { MdxControl, setupPreview } from 'netlify-cms-widget-mdx';
import remarkEmojiPlugin from 'remark-emoji';
import CoolQuote from '../components/cool-quote';
window.CMS.registerWidget(
'mdx',
MdxControl,
setupPreview({
allowedImports: {
'../../components/cool-quote': { ImportDefault: CoolQuote }
},
mdPlugins: [remarkEmojiPlugin],
})
);
it used to be
window.CMS.registerWidget(
'mdx',
MdxControl,
setupPreview({
scope: {
CoolQuote: ({ children, ...props }) => (
<CoolQuote {...props}>
{children}
</CoolQuote>
)
},
components: {},
allowedImports: {},
mdPlugins: [remarkEmojiPlugin],
})
);
May be the failure is because of my setup. I have a separate webpack build for my cms/cms.js
which outputs cms.bundle.js
in the public folder of my next.js app. ( referred and modified from https://github.com/Jinksi/netlify-cms-react-starter/blob/master/cms/webpack.config.js ).
// This webpack config is used to compile the JS for the CMS
const path = require('path')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const production = process.env.NODE_ENV === 'production'
const mode = production ? 'production' : 'development'
// const mode = 'production'
console.log(`Building CMS in ${mode} mode`)
module.exports = {
entry: './cms.js',
output: {
filename: 'cms.bundle.js',
path: path.resolve(__dirname, '../public/admin/'),
},
mode,
stats: { warnings: false, children: false },
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: [
'babel-plugin-styled-components',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-class-properties'
],
},
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: [
{ loader: 'css-loader', options: { importLoaders: 1 } },
'postcss-loader',
],
}),
},
],
},
plugins: [
new ExtractTextPlugin({
filename: 'cms.bundle.css',
}),
],
}
from gatsby-mdx.
What's your nextjs version? I had somewhat related issue with latest nextjs versions - vercel/next.js#9022 (<=9.0.5
seems to be working fine)
from gatsby-mdx.
Related Issues (20)
- Create docs site
- Update support for @mdx-js/*@0.16.x
- Add components override mechanics via MDXProvider HOT 2
- Support alternative default export syntax
- Update @mdx-js/runtime version
- Unite with other Gatsby MDX? HOT 2
- [netlify-cms-widget-mdx] Broken compatibility with latest netlify-cms-app HOT 1
- Fix changelog links
- Fix preview image in npm
- Update to MDX v1
- No control for widget 'mdx'. HOT 11
- Better editor widget HOT 4
- mdx widget invalid mdx HOT 1
- SyntaxError: Unterminated string constant
- Props spreading + props
- TypeError: Cannot read property 'validate' of undefined
- how to configure netlify-cms-widget-mdx with NextJS ? HOT 2
- Plugin gatsby-transformer-mdx is not compatible with your gatsby version 3.2.0 - It requires gatsby@^2 HOT 1
- process.cwd is not a function error for netlify-cms-widget-mdx HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gatsby-mdx.