-
-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does not work with NextJS #52
Comments
@jdudmesh Whether it can solve the problem? |
Doesn't work for me |
The problem is that MDEditor.tsx has an import for index.less. The component will only work with NextJS if this import is removed. This requires changing react-md-editor. Consider moving the CSS for the component into a separate file which can be imported independently i.e. in _app.js. |
I'm too facing the same problem, this doesn't work in NextJS. Any way to make it working ? |
I was having the exact problem and managed to fix by installing const withCSS = require('@zeit/next-css');
module.exports = withCSS({
// Your configurations here
}); Hope that helps you, let me know if it works. |
@earthnoob thanks it works for me. |
WOOO, thank you @earthnoob. The question now is: what's the difference between the plugin and the built-in configuration? |
I would love to use this as well, but just trying to get by the sparse next.config.js information for next js I guess this probably is a no go for me using it in Nextjs. Can anyone recommend a markdown editor that does work for next? |
This does not solve the problem, it only works around it. In order to make it work as it should with next.js users need a way to import CSS by themselves instead of having it imported in the source code. |
I ran into a styling issue but I wasn't using next.js. My setup is Rails + React and the css for the editor wasn't loading properly. I created a plain css file and imported it separately and that solved my issue. It's attached as a txt cause Github says they don't support uploading css files. Figured this might be helpful for anyone that is in my position and doesn't want to hunt down all the current styles. |
Solution to > In your next.js component or page, add this>
Then, go to |
The suggested solution is now deprecated by Zeit/Vercel. Consider a proper fix and not import the CSS in the node_modules :) |
@jaywcjlove should this be reopened? Sseems like the Next.js recommendation is now to not use imports of CSS from |
@karlhorky If the above does not work, try the following.
|
Hmm... step 2 fails for some reason - same error ( https://codesandbox.io/s/nextjs-example-react-md-editor-forked-bjmoi?file=/babel.config.js Is there something misconfigured here? Error (same as above):
|
Ah maybe webpack is not configured to run the I guess if that is the case, then also Custom webpack config may be the guide to follow... |
If it doesn't work, you can only use it. For Example: https://codesandbox.io/s/nextjs-example-react-md-editor-qjhn7?file=/next.config.js:25-39 I don't want |
There seems to be things like The best would be for |
I understand this, that makes sense. I don't think it should only work in Next.js. However, many libraries instruct the users to import CSS files themselves (which makes it more flexible as well, for users without For example, in the Reach UI docs:
Maybe it would make sense to move the CSS imports out of files like Maybe the upcoming v3 would be a good time to make this potentially breaking change...? |
@jaywcjlove Is there any update on this? As the @zeit/next-css is deprecated how can we use this library? |
@stLoiz Did not expect the best of both worlds solution. |
1.Create a
Reference: https://github.com/vercel/next.js/issues/299#issuecomment-263146962 |
I just wanted to drop a quick heads up on style imports! it looks like they are not bundled with this name any more: import "@uiw/react-md-editor/dist/markdown-editor.css";
import "@uiw/react-markdown-preview/dist/markdown.css"; instead, they are: import "@uiw/react-md-editor/dist/mdeditor.min.css";
import "@uiw/react-markdown-preview/dist/markdown.min.css"; here is a screenshot of dist folder inside of node-modules that got me for 2 mins to figure it out: |
I used the plugin but I'm still encountering an error. The editor/preview seems to work fine when I navigate to the page with it via
|
solutions are 👍 install :- // next.config.js file write :- //File :- const MDEditor = dynamic( function Pages() { ); } export default Pages; |
What worked for me (Next.js version 13.4.3) is inside your next.config.mjs add the following to your config:
|
After doing all of these I am getting now webpack errors.
I am using nextjs 13.x |
For those struggling, I was able to fix this issue without installing |
As @preetpatel mentioned the only thing you have to do is use: experimental: {
esmExternals: 'loose',
}, Here I leave the code that I used in a NextJS 13.0.7 App: next.config.js // @ts-check
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone', /* This is not part of the react-md-editor configuration */
reactStrictMode: true, /* This is not part of the react-md-editor configuration */
swcMinify: true, /* This is not part of the react-md-editor configuration */
experimental: {
appDir: true, /* This is not part of the react-md-editor configuration */
esmExternals: 'loose', /* For react-md-editor */
},
},
};
module.exports = nextConfig; page.tsx (Component) 'use client';
import MDEditor, { commands } from '@uiw/react-md-editor';
import { ChangeEvent, useState } from 'react';
/* Custom button in toolbar */
const help = {
name: 'help',
keyCommand: 'help',
buttonProps: { 'aria-label': 'Insert help' },
icon: (
<svg viewBox='0 0 16 16' width='12px' height='12px'>
<path
d='M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8Zm.9 13H7v-1.8h1.9V13Zm-.1-3.6v.5H7.1v-.6c.2-2.1 2-1.9 1.9-3.2.1-.7-.3-1.1-1-1.1-.8 0-1.2.7-1.2 1.6H5c0-1.7 1.2-3 2.9-3 2.3 0 3 1.4 3 2.3.1 2.3-1.9 2-2.1 3.5Z'
fill='currentColor'
/>
</svg>
),
// eslint-disable-next-line no-unused-vars
execute: (state: any, api: any) => {
window.open('https://www.markdownguide.org/basic-syntax/', '_blank');
},
};
export default function Page() {
const [value, setValue] = useState<string | undefined>('**Hello world!!!**');
const handleChange = (
value?: string | undefined,
// eslint-disable-next-line no-unused-vars
event?: ChangeEvent<HTMLTextAreaElement> | undefined,
) => {
setValue(value);
console.log('markdown: ', value);
};
return (
<div>
<MDEditor
value={value}
onChange={handleChange}
commands={[...commands.getCommands(), help]}
/>
{/* (val) => setValue(val) */}
</div>
);
} As you can see there is no need to install additional packages like next-remove-imports or use specific NextJS imports for the component. |
You can use 'next-transpile-modules' instead of 'next-remove-imports'. (using next.js page router) // next.config.mjs
import withTM from 'next-transpile-modules'
const WithTM = withTM(['@uiw/react-md-editor', '@uiw/react-markdown-preview'])
const nextConfig = {
...
}
export default WithTM(nextConfig) |
NextJS does not allow global CSS to be imported at the component level, only in _app.js.
See https://codesandbox.io/s/compassionate-cookies-msmsd?file=/pages/index.js
The text was updated successfully, but these errors were encountered: