Question

I just installed sails@v0.9.16, express@4.0.0, compression@1.0.1 and compress@0.1.9 (just to make sure). But I still have following error when running sails lift

/Users/myuser/myproject/backend/node_modules/express/lib/express.js:89
      throw new Error('Most middleware (like ' + name + ') is no longer bundle
            ^
Error: Most middleware (like compress) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.
    at Function.Object.defineProperty.get (/Users/myuser/myproject/backend/node_modules/express/lib/express.js:89:13)
    at Object.module.exports.express.customMiddleware (/Users/myuser/myproject/backend/config/passport.js:127:20)
    at Array.loadExpress [as 1] (/usr/local/lib/node_modules/sails/lib/express/index.js:162:25)
    at listener (/usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:462:46)
    at /usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:416:17
    at Array.forEach (native)
    at _each (/usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:32:24)
    at Object.taskComplete (/usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:415:13)
    at processImmediate [as _immediateCallback] (timers.js:330:15)

Any idea why?

Était-ce utile?

La solution

Sails does not officially support Express 4; there's a reason the Express dependency in the Sails package.json is set to an explicit version! You can use the other answers here to try and get your Sails app running, but you're on your own until we update the core to make use of the new Express.

We are planning on reaching out to the Express team to try and synchronize releases better in the future, but at the moment we're working hard on getting out a stable release of Sails v0.10!

Autres conseils

It's not enough to just install those dependencies in express 4.0.

You now need to include them in Your app with

var compression = require('compression');

and then use it.

There is quite nice article here: link
and also here: link

on how to deal with migrating from expres 3.x.x to 4.x.x

Express 4.0's middleware documentation says,

As of 4.x, Express no longer depends on Connect. All of Express' previously included middleware are now in separate repos. Please view the list of middleware. The only included middleware is now express.static().

So, you have to explicitly include all the needed middlewares in the package.json, as a dependency. See the link in the quoted text to get to know the repository information of all the middlewares.

https://github.com/expressjs/body-parser/issues/31 change your bodyParser() to app.use(bodyParser.json()) app.use(bodyParser.urlencoded({ extended: true })) Maybe you'll get the right answer. since express version 3 to 4, body-parser is not in express,you should install it independencly. May help you.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top