react-monaco-editor: Error: cannot find 'monaco-editor'

I’ve been getting the this when I try to use this package (latest with monaco-editor v0.13.1):

Here’s my webpack build:

const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');

module.exports = {
  mode:'development',
  devtool: 'source-map',
  optimization: {
    splitChunks:{}
  },
  entry: {
    app: './ui/client/index.js'
  },
  context: path.resolve(__dirname),
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js',
    publicPath: '/dist/'
  },
  plugins: [
    new ExtractTextPlugin('styles.css'),
    new webpack.DefinePlugin({
      "process.env": {
        BROWSER: JSON.stringify(true)
      }
    }),
    new MonacoWebpackPlugin()
  ],
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        include: path.resolve(__dirname),
        use: {
          loader: "babel-loader"
        }
      },
      {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })
      }
    ]
  }
};

Any idea why? I’d appreaciate your response!

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 18 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I ran into pretty much the same thing with jest in test using this module,

 FAIL  __tests__/components/Layout.spec.js
  ● Test suite failed to run

    Cannot find module 'monaco-editor' from 'editor.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
      at Object.<anonymous> (node_modules/react-monaco-editor/lib/editor.js:11:21)

had to “alias” monaco-editor to react-monaco-editor to help jest resolve it:

...
"moduleNameMapper": {
  "^.+\\.(css|scss)$": "identity-obj-proxy",
  "monaco-editor": "<rootDir>/node_modules/react-monaco-editor"
},
...

Hey @expobrain, sorry I should’ve included it initially. Here’s the full error:

Error: Cannot find module 'monaco-editor'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/irfanbaqui/ia-app/node_modules/react-monaco-editor/lib/editor.js:11:21)
    at Module._compile (module.js:652:30)
    at Module._compile (/Users/irfanbaqui/ia-app/node_modules/pirates/lib/index.js:91:24)
    at Module._extensions..js (module.js:663:10)
    at Object.newLoader [as .js] (/Users/irfanbaqui/ia-app/node_modules/pirates/lib/index.js:96:7)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/irfanbaqui/ia-app/node_modules/react-monaco-editor/lib/index.js:8:15)
    at Module._compile (module.js:652:30)

I’m using @monaco-editor/react package and I followed the suggestion above comment by @sanusart . Thanks

This works for me:

    "transformIgnorePatterns": [
      "/node_modules/(?!(monaco-editor)).+\\.js$"
    ],
    "moduleNameMapper": {
      "^monaco-editor$": "<rootDir>/node_modules/@monaco-editor/react"
    }

I ran into the same issue too. 😦

I ran into the same issue. 😦