Error: Cannot find module 'monaco-editor'
I've been getting the the error cannot find monaco-editor when I try to use this package (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 also tried adding an alias in webpack to consume monaco-editor/esm/vs/editor/editor.api, but the same error still persists.
monaco-editor version: 0.13.1 Browser: N/A OS: MacOSX 10.12.5
@alexandrudima the problem is that in the package.json a module property is defined for esm but there is no main for the old school.
Adding "main": "./dev/vs/editor/editor.main.js" fixes the issue.
See https://github.com/microsoft/monaco-editor/issues/1290#issuecomment-459075707 and https://github.com/Microsoft/monaco-editor/issues/1288#issuecomment-524352892
I believe this has been resolved in the meantime because all the webpack samples at https://github.com/microsoft/monaco-editor-samples work for me now.