代码之家  ›  专栏  ›  技术社区  ›  Ras

带Express Js:TypeError:\u sentence$.get(…).do的Mikronode不是函数

  •  0
  • Ras  · 技术社区  · 6 年前

    我想在Express Js中使用Mikronode,但是出现了一个错误 TypeError: _sentence$.get(...).do is not a function 第一次跑步。

    我使用 Express generator 并尝试Mikronode代码示例 wiki.mikrotik.com

    这是代码:

    var createError = require('http-errors');
    var express = require('express');
    var path = require('path');
    var cookieParser = require('cookie-parser');
    var logger = require('morgan');
    var api = require('mikronode');
    
    var indexRouter = require('./routes/index');
    var usersRouter = require('./routes/users');
    
    var app = express();
    
    // view engine setup
    app.set('views', path.join(__dirname, 'views'));
    app.set('view engine', 'pug');
    
    app.use(logger('dev'));
    app.use(express.json());
    app.use(express.urlencoded({ extended: false }));
    app.use(cookieParser());
    app.use(express.static(path.join(__dirname, 'public')));
    
    app.use('/', indexRouter);
    app.use('/users', usersRouter);
    
    // Mikronode example code
    var connection = new api('192.168.0.1','admin','password');
    connection.connect(function(conn) {
    
       var chan=conn.openChannel();
    
       chan.write('/ip/address/print',function() {
          chan.on('done',function(data) {
    
             var parsed = api.parseItems(data);
    
             parsed.forEach(function(item) {
                console.log('Interface/IP: '+item.interface+"/"+item.address);
             });
    
             chan.close();
             conn.close();
    
          });
       });
    });
    
    // catch 404 and forward to error handler
    app.use(function(req, res, next) {
        next(createError(404));
    });
    
    // error handler
    app.use(function(err, req, res, next) {
        // set locals, only providing error in development
        res.locals.message = err.message;
        res.locals.error = req.app.get('env') === 'development' ? err : {};
    
        // render the error page
        res.status(err.status || 500);
        res.render('error');
    });
    
    module.exports = app;
    

    如果我运行上面的代码,输出将显示一个错误:

    /Users/me/Desktop/mknode/node_modules/mikronode/dist/mikronode.js:474
                    _parsed$.set(this, _sentence$.get(this).do(function (d) {
                                                              ^
    
    TypeError: _sentence$.get(...).do is not a function
        at new SocketStream (/Users/me/Desktop/mknode/node_modules/mikronode/dist/mikronode.js:474:52)
        at MikroNode.connect (/Users/me/Desktop/mknode/node_modules/mikronode/dist/mikronode.js:330:30)
        at Object.<anonymous> (/Users/me/Desktop/mknode/app.js:31:12)
        at Module._compile (module.js:643:30)
        at Object.Module._extensions..js (module.js:654:10)
        at Module.load (module.js:556:32)
        at tryModuleLoad (module.js:499:12)
        at Function.Module._load (module.js:491:3)
        at Module.require (module.js:587:17)
        at require (internal/module.js:11:18)
    error Command failed with exit code 1.
    

    我的包.json:

    {
      "name": "mknode",
      "version": "0.0.0",
      "private": true,
      "scripts": {
        "start": "node ./bin/www"
      },
      "dependencies": {
        "cookie-parser": "~1.4.3",
        "core-decorators": "^0.20.0",
        "debug": "~2.6.9",
        "express": "~4.16.0",
        "http-errors": "~1.6.2",
        "mikronode": "^2.3.11",
        "morgan": "~1.9.0",
        "pug": "2.0.0-beta11",
        "rxjs": "^6.2.2"
      }
    }
    

    有人能帮我解决这个问题吗?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Asep Kohar    6 年前

    通过安装“rxjs”解决此问题:“^5.3.0”