Maybe try using @monaco-editor/react package. You can get the monaco instance using the useMonaco hook. Using that, you can register your language. Not sure any of the above works. Just saying options Answer from 0x006e on reddit.com
🌐
GitHub
github.com › react-monaco-editor › react-monaco-editor › issues › 136
Custom Language sample · Issue #136 · react-monaco ...
July 5, 2018 - <script> var require = { paths: { 'vs/language/athena': 'http://localhost:8080/release/dev', 'vs': '../node_modules/monaco-editor-core/dev/vs' } }; </script> <script src="../node_modules/monaco-editor-core/dev/vs/loader.js"></script> <script src="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.nls.js"></script> <script src="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.js"></script> <script> require([ 'vs/language/athena/src/monaco.contribution' ], function() { monaco.languages.register({ id: 'athena', extensions: ['.athena'], }); }); </script>
Author   pointnet
🌐
npm
npmjs.com › package › @monaco-editor › react
monaco-editor/react
In most cases it's okay, but the developers face problems when they want to implement a multi-model editor to support tabs/files like in IDEs. And previously to handle multiple models they had to do it manually and out of the component. Now, the multi-model API is supported 🎉 Let's check how it works. There are three parameters to create a model - value, language and path (monaco.editor.createModel(value, language, monaco.Uri.parse(path))).
      » npm install @monaco-editor/react
    
Published   Feb 13, 2025
Version   4.7.0
Author   Suren Atoyan
🌐
Stack Overflow
stackoverflow.com › questions › 78779441 › monaco-editor-custom-language
typescript - Monaco Editor Custom Language - Stack Overflow
import React, { useEffect } from 'react' import Editor, { useMonaco } from '@monaco-editor/react' // Adjusted config to only highlight curly braces export const languageDef = { defaultToken: '', brackets: [['{', '}', 'delimiter.curly']], tokenizer: { root: [ [/{/, 'delimiter.curly'], // Token for opening curly brace [/}/, 'delimiter.curly'], // Token for closing curly brace ], }, } const configuration = { base: 'vs', inherit: true, rules: [ { token: 'delimiter.curly', foreground: 'FF0000', fontStyle: 'bold' }, // Styling for curly braces ], } export default function TractaEditor({ value, onCha
🌐
Reddit
reddit.com › r/reactjs › integrating monaco editor with multi-language support & intellisense in react ts
r/reactjs on Reddit: Integrating Monaco Editor with Multi-Language Support & IntelliSense in React TS
September 11, 2024 -

I’m currently working on integrating Monaco Editor into a React TypeScript project to support multiple languages (JavaScript, TypeScript, Python, Java) with IntelliSense using Language Server Protocol (LSP). I’ve been struggling to find clear and working resources or examples for this setup.

My Challenges:

  • Configuring Monaco Editor to work with multiple languages.

  • Setting up LSP to enable IntelliSense (autocomplete, error highlighting).

What I’m Looking For:

  • Guidance on how to set up Monaco Editor with LSP in React TS.

  • Any working examples, code snippets, or reliable documentation links.

I’ve tried various tutorials, but none seem to work fully or fit my requirements. I would be really grateful for any help, advice, or pointers you can provide!

lsp #monaco #language-server

🌐
Better Programming
betterprogramming.pub › create-a-custom-web-editor-using-typescript-react-antlr-and-monaco-editor-part-1-2f710c69c18c
Create a Custom Web Editor Using TypeScript, React, ANTLR, and Monaco Editor | by Amazzal El-habib | Better Programming
March 30, 2022 - npm add react react-domnpm add -D typescript @types/react @types/react-dom ts-loader html-webpack-plugin webpack webpack-cli webpack-dev-server · Create an src directory with your entry point index.tsand index.html that contains a div with an id container. Here is the source code for this starter project. If you are targeting an existing language like TypeScript, HTML, or Java, you don’t have to reinvent the wheel. Monaco Editor and Monaco Languages support most of those languages.
🌐
GitHub
github.com › react-monaco-editor › react-monaco-editor
GitHub - react-monaco-editor/react-monaco-editor: Monaco Editor for React. · GitHub
Replace react-scripts by react-app-rewired in the scripts section of your packages.json · Create a config-overrides.js in the root directory of your project with the following content: const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); module.exports = function override(config, env) { config.plugins.push(new MonacoWebpackPlugin({ languages: ['json'] })); return config; }
Starred by 4.2K users
Forked by 389 users
Languages   TypeScript 67.0% | JavaScript 31.7% | HTML 1.3%
🌐
Reddit
reddit.com › r/reactjs › how can i turn the monaco editor into a react component using my own language definition (js file) (require is not defined...)
r/reactjs on Reddit: How can i turn the monaco editor into a react component using my own language definition (js file) (require is not defined...)
May 15, 2023 -

I am working on a monaco editor with my own language definition (mylang, it's a js file). Frontend is working with HTML. note: the editor has to be compatible with react (maybe its not even necessary to implement the editor as a react component?)

turning the monaco editor into a react component works, but as soon as i link the language definition file to the editor, it stops working and i get the require is not defined error and if i do it without the require function it doesnt recognize the editor anymore.

 <!-- load language, somehow its not working with our language definition (mylang.js). there is a problem with the require command in mylang -->
<!-- in this file the monaco editors language is javascript (see line 34)  -->


<script src="./mylang.js"></script>


<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>React Monaco Editor Example</title>
    <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/monaco-editor@0.25.2/min/vs/loader.js"></script>
  </head>
  <body>
    <div id="root"></div>
    <script>
      // Define a React component that uses the Monaco editor
      class MonacoEditor extends React.Component {
        constructor(props) {
          super(props);

          this.state = {
            editorValue: "",
          };

          // Load the Monaco editor
          require.config({ paths: { vs: "https://unpkg.com/monaco-editor@0.25.2/min/vs" } });
          require(["vs/editor/editor.main"], () => {
            // Initialize the editor
            const editor = monaco.editor.create(document.getElementById("container"), {
              value: "",
              language: "mylang",
              lineNumbers: false
            });
          });
        }
        
        render() {
        return React.createElement(
        'div',
        null,
        React.createElement('div', { id: 'container', style: { height: '400px', width: '800px' } }),
        React.createElement('pre', null, this.state.editorValue)
        );
        }
        
      }

      // Render the MonacoEditor component to the root element
      ReactDOM.render(React.createElement(MonacoEditor, null), document.getElementById("root"));    
      </script>
  </body>
</html>

and this is the beginning of my language definition file:

require(['vs/editor/editor.main'], function() {
    // Define the language
    monaco.languages.register({ id: 'mylang' });
    
    // Define the list of keywords
    const mylangKeywords = [
      'continue', 'for', 'and', 'or',....
🌐
GitHub
github.com › suren-atoyan › monaco-react
GitHub - suren-atoyan/monaco-react: Monaco Editor for React - use the monaco-editor in any React application without needing to use webpack (or rollup/parcel/etc) configuration files / plugins · GitHub
In most cases it's okay, but the developers face problems when they want to implement a multi-model editor to support tabs/files like in IDEs. And previously to handle multiple models they had to do it manually and out of the component. Now, the multi-model API is supported 🎉 Let's check how it works. There are three parameters to create a model - value, language and path (monaco.editor.createModel(value, language, monaco.Uri.parse(path))).
Starred by 4.7K users
Forked by 318 users
Languages   TypeScript 93.2% | JavaScript 4.6% | CSS 1.2% | HTML 1.0%
Find elsewhere
🌐
GitHub
github.com › react-monaco-editor › react-monaco-editor › issues › 312
Custom language syntax highlighting seems not to work · Issue #312 · react-monaco-editor/react-monaco-editor
September 28, 2020 - Describe the bug After defining a custom language, syntax highlighting only works for the first line of code. I tried reproducing the issue on Monaco editor playground but it works as expected there. ... import * as monaco from "monaco-editor/esm/vs/editor/editor.api"; import * as React from "react"; import MonacoEditor from "react-monaco-editor"; import { ReactElement } from "react"; export default class App extends React.Component { constructor(props: Record<string, unknown>) { super(props); } editorWillMount(monacoEditor: typeof monaco): void { monacoEditor.languages.register({ id: "8080asm
Author   mac501pl
🌐
DevGenius
blog.devgenius.io › create-a-web-editor-using-monaco-editor-react-and-node-webpack-and-typescript-how-hard-can-it-597332454a24
[Part 1] Create a web editor using Monaco editor, React and Node + Webpack and Typescript … How hard can it be? | by Nipuna Marcus | Dev Genius
June 4, 2024 - Also you can register your own language here and add syntax highlighting and Language features for that language. But here I will add an already supported language in Monaco Editor, JSON.
🌐
Snyk
snyk.io › advisor › monaco-editor › functions › monaco-editor.languages
How to use the monaco-editor.languages function in monaco-editor | Snyk
December 2, 2020 - ggoodman / velcro / packages / playground / src / lib / EditorManager.ts View on Github · inlineSourceMap: true, inlineSources: true, isolatedModules: false, jsx: Monaco.languages.typescript.JsxEmit.React, lib: ['dom'], module: Monaco.languages.typescript.ModuleKind.CommonJS, moduleResolution: Monaco.languages.typescript.ModuleResolutionKind.NodeJs, noEmit: false, outDir: `dist`, resolveJsonModule: true, rootDir: '/', sourceMap: true, target: Monaco.languages.typescript.ScriptTarget.ES2015, typeRoots: ['node_modules/@types'], }); Monaco.languages.typescript.typescriptDefaults.setDiagnosticsOp
🌐
Surenatoyan
monaco-react.surenatoyan.com
Monaco Editor React
Monaco editor wrapper for easy integration with React applications
Top answer
1 of 3
9

If you are using the Monaco editor with create-react-app you will need a different approach, if you don't want to eject the app (to allow manually editing the webpack config file). This paragraph describes it pretty well:

The easiest way to use the react-monaco-editor with create-react-app is to use the react-app-rewired project. For setting it up, the following steps are required:

  • Install react-app-rewired: npm install -D react-app-rewired
  • Replace react-scripts by react-app-rewired in the scripts section of your packages.json
  • Create a config-overrides.js in the root directory of your project with the following content:
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');

module.exports = function override(config, env) {  
    config.plugins.push(new MonacoWebpackPlugin({
        languages: ['json']
    }));
    return config;
}

For more information checkout the documentation of react-app-rewired here.

I did not have to specify anything else to make it work. No need to specify loaders for webpack manually.

2 of 3
4

For me both of the above answers are not working - not sure if it's related to Codesandbox or I did a mistake.

But using @monaco-editor/react is working with-out any changes to the CRA setup.

The only difference in the usage is that the default export is not a controlled component - so onchange is not working.

To have a controlled component, just use import {ControlledEditor as MonacoEditor} from "@monaco-editor/react". The onchange handler needs to be slightly modified, first the event & then the newText - just a small difference in the implementation.

The usage looks like following:

import React, { useState } from "react";
import { ControlledEditor as MonacoEditor } from "@monaco-editor/react";
export const Editor = () => {
  const [code, setCode] = useState(`const greeting = () => {
    alert("Hello world");
}`);

  const options = {
    minimap: {
      enabled: false
    }
  };

  const changeHandler = (evt, newText) => {
    setCode(newText);
  };

  const editorDidMount = (editor, monaco) => {
    console.log("editorDidMount", editor);
  };

  return (
    <MonacoEditor
      width="100%"
      height="100%"
      language="javascript"
      theme="vs-dark"
      value={code}
      options={options}
      onChange={changeHandler}
      editorDidMount={editorDidMount}
    />
  );
};

The options can be used to modify the Monaco editor. In my case I don't want to display the minimap. All available options can be found in the editor api docs

You can find the working demo in this Codesandbox.

The only thing that I found that is not working is undo/redo as described in the following issue. No change event triggered but I'll check this later - for now I'm happy with it.

Top answer
1 of 2
2

You should be able to use the following code to configure an autocomplete that converts text typed in English to the fantasy language. As you're using React and TypeScript you might need to convert it slightly.

function createDependencyProposals(range) {
    return [
    {
      documentation: 'beautiful',
      insertText: 'byut',
      kind: monaco.languages.CompletionItemKind.Keyword,
      label: 'beautiful',
      range: range
    },
    {
      documentation: 'faster',
      insertText: 'fsut',
      kind: monaco.languages.CompletionItemKind.Keyword,
      label: 'faster',
      range: range
    }
  ]
}

// Register the custom language
monaco.languages.register({id: 'bead'});

// Register the completion provider
monaco.languages.registerCompletionItemProvider('bead', {
    provideCompletionItems: function (model, position) {
        // Get the text before the cursor
      var word = model.getWordUntilPosition(position);
      var range = {
        startLineNumber: position.lineNumber,
        endLineNumber: position.lineNumber,
        startColumn: word.startColumn,
        endColumn: word.endColumn,
      };
      // Compute the suggestions
      return {
        suggestions: createDependencyProposals(range),
      };
    }
});

monaco.editor.create(document.getElementById("container"), {
    value: '',
    language: "bead",
});

According to this, triggerCharacters are additional characters other than a-z that will also trigger suggestions (e.g. if you want to trigger suggestions when typing ., ! etc), so you won't need to define any explicit trigger characters if you just want to trigger suggestions when typing `a-z.

Here's a working Monaco Playground demo. You should be able to start typing the English word, e.g. type bea, the suggestion beautiful will appear, and if you select it (press Enter or click on it), it will insert the Bead word into the editor.

2 of 2
1

Seems like monaco won't trigger if your tokenizer is matching string, here:

export const languageDef = {
  defaultToken: '',
  tokenizer: {
    root: [{ include: '@whitespace' }, { include: '@strings' }],
    strings: [[/\w+/, 'string']],
    whitespace: [[/\s+/, 'white']],
  },
}

the @strings rule matches \w+ as soon as you type a char, marking it a string token class thus autocompletion will not trigger, you can fix it by changing string to identifier

🌐
GitHub
github.com › suren-atoyan › monaco-react › issues › 118
How to integrate a custom language's web worker into this library? · Issue #118 · suren-atoyan/monaco-react
October 14, 2020 - // this is what @monaco-editor/react provided // App.js function App() { // ... return ( <Editor height="90vh" language="myLang" value="" editorDidMount={handleEditorDidMount} /> ) } // this is the web worker i want customize // myLang.worker.js self.onmessagee = () => { // ...
Author   hacker0limbo
🌐
GitHub
microsoft.github.io › monaco-editor
Monaco Editor
The index of Microsoft GitHub repositories that are open source has been relocated to https://opensource.microsoft.com
🌐
Checkly
checklyhq.com › blog › custom monaco editor
Monaco Editor Custom Language & Code Completion
February 23, 2024 - While trying to replicate this feature in Monaco, we realized we would have to create an entirely custom language feature and bolt it onto the built-in Javascript language definitions and handler in Monaco.
🌐
LogRocket
blog.logrocket.com › home › build a web editor with react-monaco-editor
Build a web editor with react-monaco-editor - LogRocket Blog
June 4, 2024 - We also need to install some dependencies to work with the react-monaco-editor. Install them by running the command below: yarn add monaco-editor monaco-editor-core monaco-languageclient
🌐
Stack Overflow
stackoverflow.com › questions › 76162348 › how-can-i-turn-the-monaco-editor-into-a-react-component-using-my-own-language-de
How can i turn the monaco editor into a react component using my own language definition (js file) (require is not defined...)
require(['vs/editor/editor.main'], function() { // Define the language monaco.languages.register({ id: 'mylang' }); // Define the list of keywords const mylangKeywords = [ 'continue', 'for', 'and', 'or',.... ... How to pass in a react component ...
🌐
OpenReplay
blog.openreplay.com › create-your-own-code-editor-with-react
Create your own Code Editor with React
April 23, 2024 - Languages and Technologies: React ... like JavaScript, TypeScript, Python, Java, C++, and many more. You can also extend it for custom languages....