scniro / react-codemirror2

Codemirror integrated components for React
MIT License
1.66k stars 193 forks source link

Getting "cm is not a function" in NextJs #298

Open Vasu7389 opened 1 year ago

Vasu7389 commented 1 year ago

Hi, I am getting the below error in NextJs. I have tried downgrading the version but it is not getting resolved. Please help!

The versions I have tried - v7.2.1 (latest) v7.1.0 v7.0.0 v6.0.1

Unhandled Runtime Error
TypeError: cm is not a function

Call Stack
Controlled.componentDidMount
node_modules\react-codemirror2\index.js (498:0)
commitLayoutEffectOnFiber
node_modules\react-dom\cjs\react-dom.development.js (23305:0)
commitLayoutMountEffects_complete
node_modules\react-dom\cjs\react-dom.development.js (24688:0)
commitLayoutEffects_begin
node_modules\react-dom\cjs\react-dom.development.js (24674:0)
commitLayoutEffects
node_modules\react-dom\cjs\react-dom.development.js (24612:0)
b7wch commented 1 year ago

I have the same problem.

Uncaught TypeError: cm is not a function
shmjiao commented 1 year ago

I encountered this problem on react18. When react17 was executed, no error was reported, is also nextjs.

ruanjiayou commented 1 year ago

i saw this on error page

var React = require('react');

var SERVER_RENDERED = typeof navigator === 'undefined' || global['PREVENT_CODEMIRROR_RENDER'] === true;
var cm;

if (!SERVER_RENDERED) {
  cm = require('codemirror');
}
filip-savic-bm commented 5 months ago

solution - get codemirror@5

I had same problem: "react-codemirror2": "^8.0.0", "react": "^18.2.0", "codemirror": "^6.0.1",

Error goes away when i uninstall install codemirror and install codemirror@5 -- which gets me to "codemirror": "^5.65.16"