question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

require('codemirror') loads react-codemirror component

See original GitHub issue

I’ve tried to embed react-codemirror into the app as described in the example, but faced strange issue. I got an error TypeError: CM.fromTextArea is not a function.

After some investigation, I found that react-codemirror loads itself here https://github.com/JedWatson/react-codemirror/blob/master/lib/Codemirror.js#L6

CM contains CodeMirror react component.

I’m bundling project with webpack and babel. Result bundle contains 2 equal module IDs 648 and 649, and 649 depends on 648, react-codemirror both.

Here is a sample of webpack config:

module.exports = {
  context: join(__dirname, '/src'),

  entry: {
    app: [
      'babel-polyfill',
      './scripts/master',
      './index.html'
    ]
  },

  output: {
    path: join(__dirname, '/dist'),
    filename: '[name].js'
  },

  debug: true,

  devtool: null,

  module: {
    loaders: [
      {
        test: /(\.js|\.jsx)$/,
        include: [
          join(__dirname, 'src'),
          join(__dirname, 'node_modules/react-codemirror')
        ],
        loader: 'babel'
      },
      {
        test: /(\.scss|\.css)$/,
        loader: ExtractTextPlugin.extract('style', 'css?sourceMap&modules&importLoaders=1&' +
          'localIdentName=[name]__[local]___[hash:base64:5]!postcss!sass?sourceMap!toolbox')
      },
    ]
  },
  resolve: {
    extensions: ['', '.js', '.jsx', '.json', '.scss', '.css'],
    modulesDirectories: [
      'node_modules',
      'src/scripts',
      'src'
    ]
  },

};

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:6

github_iconTop GitHub Comments

6reactions
zenoamarocommented, May 21, 2016

@balkonsmoke, @joshbuckley182, the issue is caused by these lines in your webpack configurations:

modulesDirectories: [
  'node_modules',
  'src/scripts',
  'src'
]

This causes react-codemirror to look for codemirror in its own src directory before looking in node_modules. I would suggest changing that to something like:

modulesDirectories: [
  'node_modules',
  path.resolve(__dirname, 'src/scripts'),
  path.resolve(__dirname, 'src')
]
0reactions
scnirocommented, Jun 2, 2017

If this issue still persists please give react-codemirror2 a look. I’m planning on maintaining this moving forward. Better docs will be coming. Feel free to open up any issues/suggestions as I’ll be trying to gather as much constructive feedback from the community moving forward

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-codemirror - npm
Start using react-codemirror in your project by running `npm i ... Require the CodeMirror component and render it with JSX: var React ...
Read more >
scniro/react-codemirror2: Codemirror integrated ... - GitHub
requiring codemirror resources​​ Since codemirror ships mostly unconfigured, the user is left with the responsibility for requiring any additional resources ...
Read more >
[Help] Running into loader-related issue when trying to use ...
Hi, I'm just starting out with programming and trying to implement CodeMirror into a Javascript React project I'm working on.
Read more >
React CodeMirror v4.19.5
CodeMirror allows to serialize editor state to JSON representation with toJSON function for persistency or other needs. This JSON representation can be later ......
Read more >
CodeMirror component for React
requiring codemirror resources, This is often the case when specifying certain language modes and themes. Just set the mode, the language ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found