我只是想运行使用 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,但仍然出现相同的错误