你好,我正在尝试使一些Javascript文件可以在nodeJS上正常运行,但是一切都设置妥当,但这是我得到的错误:
ReferenceError: navigator is not defined
at C:\Users\blaster\node_modules\mxgraph\javascript\dist\build.js:45:9
at Object.<anonymous> (C:\Users\blaster\Desktop\projet\entrainement_mxgraph\test_mxgraph.js:3:33)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
我尝试为学校的项目在nodeJs下创建代码“ hello world”的示例,在nodeJs和项目javascript的概念上我还是一个新手,我的问题也许很简单或基本,但是我为此感到困惑昨天以来的小时数
这是我的代码:
var express = require('express');
var mxgraph = require("mxgraph")({
mxImageBasePath: "./src/images",
mxBasePath: "mxgraph-master/mxgraph-master/javascript/src"
})
var mxEvent = mxgraph.mxEvent;
mxEvent.disableContextMenu(container);
var app = express();
app.get('/', function(req, res) {
// Checks if the browser is supported
if (!mxClient.isBrowserSupported())
{
// Displays an error message if the browser is not supported.
mxUtils.error('Browser is not supported!', 200, false);
}
else
{
// Disables the built-in context menu
mxEvent.disableContextMenu();
// Creates the graph inside the given container
var graph = new mxGraph();
// Enables rubberband selection
new mxRubberband(graph);
// Gets the default parent for inserting new cells. This
// is normally the first child of the root (ie. layer 0).
var parent = graph.getDefaultParent();
// Adds cells to the model in a single step
graph.getModel().beginUpdate();
try
{
var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30);
var v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30);
var e1 = graph.insertEdge(parent, null, '', v1, v2);
}
finally
{
// Updates the display
graph.getModel().endUpdate();
}
}
});
app.listen(8080);
谢谢大家。