1

每当我启动 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>

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

4

1 回答 1

0

看起来 vs/language/typescript/typescriptServices.js 中的 getNodeSystem() 函数尝试要求基本节点模块,但如果您已经要求它们,那么它将返回错误。

一种 hacky 解决方案,但目前可行的是用已经定义的版本替换它们的定义。如果有人有更好的解决方法,请告诉我。抄送@estus

function getNodeSystem() {
            // var _fs = require("fs");
            // var _path = require("path");
            // var _os = require("os");
            var _fs = fs;
            var _path = path;
            var _os = os; 
            [...]
}
于 2018-07-09T20:50:45.467 回答