开发者

Express framework giving a very strange error

开发者 https://www.devze.com 2023-02-14 01:22 出处:网络
I\'m trying to use Express in node, install everything okay, compiled, got npm and installed express with:

I'm trying to use Express in node, install everything okay, compiled, got npm and installed express with:

npm install express

The problem is, everytime I try to "require" it, it gives me an error! Take a look, a simple file app.js as:

var express = require('express');

When I run it:

tlab065:~/proj/Express-server-abstraction> node app.js 
node.js:116
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
TypeError: Cannot read property 'prototype' of undefined
    at Object.<anonymous> (/people/home/jdomingues/local/node/lib/node/.npm/express/1.0.开发者_StackOverflow7/package/lib/express/server.js:87:44)    
    at Module._compile (module.js:373:26)
    at Object..js (module.js:379:10)
    at Module.load (module.js:305:31)
    at Function._load (module.js:271:10)
    at require (module.js:317:19)
    at Object.<anonymous> (/people/home/jdomingues/local/node/lib/node/.npm/express/1.0.7/package/lib/express/index.js:28:31)
    at Module._compile (module.js:373:26)
    at Object..js (module.js:379:10)
    at Module.load (module.js:305:31

Can someone help me? Why am I getting this error? How can I maybe install a different version from express?


The issue is that you probably have the latest connect (as opposed to "you need to install the latest connect") the command @Shripad showed is helpful and will probably show you that you have connect 1.0, yay...uh oh express isn't quite ready for 1.0 connect, do this to go back to 0.5.10:

npm install connect@0.5.10


You need to have the latest connect installed (connect@0.5.10). Make sure you check the connect version that is installed and active:

npm ls connect | grep active

The line that throws up an error references connect.Server.


commenting out the code that includes connect helped in my case.

//connect = require('connect');


try jpstrikesback answer and make sure to install the dependencys in the correct order:

npm install connect@0.5.10
npm install express@1.0.7

because npm install express will install the latest version of connect (if no one is available, and it will break) and in express/1.0.7/package/lib/express/server.js

connect = require('connect')

which seems to require the latest version of connect not the one you have required in your app.


For others (if your connect@1.0.1 doesn't uninstall with npm uninstall connect@1.0.1) I removed the actual files found at /usr/local/lib/node/connect/

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消