Skip to content

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

Open

Description

@Vasu7389

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)

Activity

  1. bursonyang commented on Mar 14, 2023

    @bursonyang

    I have the same problem.

    Uncaught TypeError: cm is not a function
    
  2. shmjiao commented on Mar 31, 2023

    @shmjiao

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

  3. ruanjiayou commented on Apr 13, 2023

    @ruanjiayou

    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');
    }
  4. filip-savic-bm commented on Apr 22, 2024

    @filip-savic-bm

    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"

  5. yunseop-dev commented on Apr 29, 2025

    @yunseop-dev

    @filip-savic-bm thanks, it helps me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions