我只是尝试使用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版本的节点版本从6.0降低到4.0,但仍然出现同样的错误
答案 0 :(得分:0)
我也在学习塞内卡的微服务 使用快递版本~4.13.4和seneca版本^ 2.0.0对我有用。
可以在此网址的seneca入门示例中找到更多信息: https://github.com/senecajs-attic/getting-started
查看他们的package.json文件。希望它有所帮助!