Open Jacques2Marais opened 1 year ago
I had the same error. You need to add "use client"
to the beginning of the file, as it seems that nextjs can't render the editor as a server component.
@Jacques2Marais @ntillier https://codesandbox.io/embed/solitary-fog-9h5r39?fontsize=14&hidenavigation=1&theme=dark
import React from "react";
import Link from "next/link";
import dynamic from "next/dynamic";
const CodeMirror = dynamic(() => import("@uiw/react-codemirror"), {
ssr: false
});
const Thing: React.FC<{ msg: string }> = (props) => {
return <div>{props.msg}</div>;
};
export default () => {
console.log("CodeMirror", CodeMirror);
return (
<div>
xxx
<CodeMirror value="console.log('hello wosrld!');" height="200px" />
Hello World. <Thing msg="hello" />
</div>
);
};
@jaywcjlove this error occurs with the new app directory (https://nextjs.org/docs/app). This video explains some of the latest features https://youtu.be/gSSsZReIFRk
I made an example here, with 3 examples https://stackblitz.com/edit/stackblitz-starters-nklft1?file=app%2Fwith-use-client%2Fpage.tsx
@ntillier https://nextjs.org/docs/messages/import-esm-externals
Support cjs
and esm
syntax, I don't know how to configure the usage of "use client"
Why This Error Occurred Packages in node_modules that are published as EcmaScript Module, need to be imported via import ... from 'package' or import('package').
You get this error when using a different way to reference the package, e. g. require()
.
import
or import()
to reference the package instead. (Recommended)import
, make sure that this is not changed by a transpiler, e. g. TypeScript or Babel.experimental.esmExternals: 'loose'
), which tries to automatically correct this error.
I am using React 18.2.0 on NextJS and get the following error whenever creating a CodeMirror component in one of my components. The code I have at the moment is as following:
And the error call stack looks as following: