Search code examples
javascriptnode.jsecmascript-6monaco-editorvisual-studio-monaco

Monaco Editor Dependencies Issue


Whenever I launch Monaco Editor (with node.js), it comes up and seems to behave okay, but I get an error message telling me that there are missing dependencies and to check the list. I can't seem to find the dependency list ( I installed via NPM), but I definitely know node.js fs module is included.

Error Message:

Uncaught Error: Check dependency list! Synchronous require cannot resolve module 'fs'. This is the first mention of this module!
at s.synchronousRequire (loader.js:27)
at s (loader.js:34)
at /Library/Application Support/rack/node_modules/monaco-edit…:7
at /Library/Application Support/rack/node_modules/monaco-edit…:7
at ts (/Library/Application Support/rack/node_modules/monaco-edit…:7)
at /Library/Application Support/rack/node_modules/monaco-edit…:7
at t._loadAndEvalScript (loader.js:20)
at loader.js:19
at tryToString (VM1651 fs.js:449)
at FSReqWrap.readFileAfterClose [as oncomplete] (VM1651 fs.js:436)

Usage:

    <script src="node_modules/monaco-editor/min/vs/loader.js"></script>
<script>
require.config({ paths: { 'vs': __dirname + '/node_modules/monaco-editor/min/vs' }});
require(['vs/editor/editor.main'], function() {
    var editor = monaco.editor.create(document.getElementById('container'), {
        value: [
            'function x() {',
            '\tconsole.log("Hello world!");',
            '}'
        ].join('\n'),
        language: 'javascript'
    });
});
</script>

Anyone else run into this issue? Thanks!


Solution

  • Looks like the getNodeSystem() function in vs/language/typescript/typescriptServices.js tries to require the base Node modules, but if you already have them required then it will return an error.

    Kind of a hacky solution, but works for now is to replace their definitions with the already defined versions. If someone has a better fix, let me know. cc @estus

    function getNodeSystem() {
                // var _fs = require("fs");
                // var _path = require("path");
                // var _os = require("os");
                var _fs = fs;
                var _path = path;
                var _os = os; 
                [...]
    }