react-codemirror2 icon indicating copy to clipboard operation
react-codemirror2 copied to clipboard

Getting "cm is not a function" in NextJs

Open Vasu7389 opened this issue 2 years ago • 5 comments
trafficstars

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)

Vasu7389 avatar Feb 17 '23 10:02 Vasu7389

I have the same problem.

Uncaught TypeError: cm is not a function

b7wch avatar Mar 14 '23 03:03 b7wch

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

shmjiao avatar Mar 31 '23 07:03 shmjiao

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');
}

ruanjiayou avatar Apr 13 '23 03:04 ruanjiayou

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"

filip-savic-bm avatar Apr 22 '24 10:04 filip-savic-bm