So, the following code works in development and fails when running in a production environment, with the error TypeError: Router.use() requires middleware function but got a Object
. I must have tried this about a hundred different ways by now all with the same result. Works in dev, not in prod.
/server/routes.js
'use strict';
export class AppRoutes
{
constructor(app)
{
this.app = app;
return function initialize(app)
{
app.use('/mail', require('./api/mail'));
}
}
}
/server/app.js
var app = express();
import { AppRoutes } from './routes';
let router = new AppRoutes();
router(app);
// start the server here
// Expose app
export default app;
Again, working in dev, broken when the ES6 is transpiled and the app is run in production. Thanks in advance for any thoughts on the matter.
update
The error is thrown on line 458 of /node_modules/express/lib/router/index.js
. This is what is being passed to Router.use()
:
{ default:
{ [Function: router]
params: {},
_params: [],
caseSensitive: undefined,
mergeParams: undefined,
strict: undefined,
stack: [ [Object], [Object] ]
}
}
Here are the versions of the dependencies I think are relevant to the error (same in prod as in dev):
node v0.12.2
And from my package.json
:
{
"express": "^4.13.3",
"babel-runtime": "^5.8.20",
"grunt-babel": "^6.0.0"
},
"devDependencies": {
"babel-core": "^5.8.34",
"babel-preset-es2015": "^6.1.18",
"babel-preset-stage-0": "^6.1.18"
}