1

我只是想运行使用 Node js 开发微服务的示例代码,它说:

var express = require('express')
var bodyParser = require('body-parser')
var cookieParser = require('cookie-parser')
var methodOverride = require('method-override')
var seneca = require('seneca')()
var argv = require('optimist').argv
var app = express()
var cors = require('cors')
var routes = require('./../routes/index')
let path = require('path')
var webpack = require('webpack')
var webpackMiddleware = require('webpack-dev-middleware')
var config = require('./../webpack.config.js')

var compiler = webpack(config)

var conf = {
   port: argv.p || 7770
}

app.engine('jsx', require('express-react-views').createEngine())
app.set('port', conf.port)
app.use(cors())
app.use('/public', express.static(path.join(__dirname,'./../public')))
app.use('/views', express.static(path.join(__dirname, './../views')))
app.use(webpackMiddleware(compiler));
app.use(cookieParser())
app.use(express.query())
app.use(bodyParser.urlencoded({extended: true}))
app.use(methodOverride())
app.use(bodyParser.json())
app.use(express.static('public'))
app.use(seneca.export('web'))  // Error line

seneca.use('./../lib/registerAPI')

app.use('/', routes)

module.exports = app

但我收到一条错误消息:

/home/quocdinh/workspace/ECommerce/ass-ECommerce/node_modules/express/lib/application.js:177
     throw new TypeError('app.use() requires middleware functions');
     ^
TypeError: app.use() requires middleware functions 
     at EventEmitter.use (/home/quocdinh/workspace/ECommerce/ass-ECommerce/node_modules/express/lib/application.js:177:11)
     at Object.<anonymous> (/home/quocdinh/workspace/ECommerce/ass-ECommerce/src/app.js:33:5) // --> line: app.use(seneca.export('web'))

我试图找到解决方案但没有效果。

我尝试添加

 app.use(require('seneca-web'))

但仍然不是

我试图将节点版本的版本从 6.0 降低到 4.0,但仍然出现相同的错误

4

1 回答 1

0

我也在用 seneca 学习微服务。
使用 express 版本 ~4.13.4 和 seneca 版本 ^2.0.0 对我有用。

更多信息可以在这个 URL 的 seneca 入门示例中找到: https ://github.com/senecajs-attic/getting-started

查看他们的 package.json 文件。希望能帮助到你!

于 2016-11-03T04:26:51.747 回答