摩纳哥编辑依赖性问题

时间:2018-07-09 16:25:14

标签: javascript node.js ecmascript-6 monaco-editor visual-studio-monaco

每当我启动Monaco编辑器(带有node.js)时,它就会出现并且看起来还不错,但是我收到一条错误消息,告诉我缺少依赖项并检查列表。我似乎找不到依赖项列表(我是通过NPM安装的),但我绝对知道其中包含了node.js fs模块。

错误消息:

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)

用法:

    <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>

还有其他人遇到这个问题吗?谢谢!

1 个答案:

答案 0 :(得分:0)

像vs / language / typescript / typescriptServices.js中的getNodeSystem()函数一样,它尝试需要基本的Node模块,但是如果您已经需要基本的Node模块,那么它将返回错误。

种类繁多的解决方案,但目前可以用已经定义的版本替换它们的定义。如果有人有更好的解决方案,请告诉我。 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; 
            [...]
}