2014-09-03 60 views
2

請參見下面的 '連接':找不到模塊在Windows 7

C:\Program Files\nodejs>npm -g install connect 
npm http GET https://registry.npmjs.org/connect 
npm http GET https://registry.npmjs.org/connect 
npm http GET https://registry.npmjs.org/connect 
npm http GET https://registry.npmjs.org/finalhandler/0.1.0 
npm http GET https://registry.npmjs.org/debug/1.0.4 
npm http GET https://registry.npmjs.org/parseurl 
npm http GET https://registry.npmjs.org/utils-merge/1.0.0 
npm http GET https://registry.npmjs.org/utils-merge/1.0.0 
npm http GET https://registry.npmjs.org/finalhandler/0.1.0 
npm http GET https://registry.npmjs.org/parseurl 
npm http GET https://registry.npmjs.org/debug/1.0.4 
npm http GET https://registry.npmjs.org/utils-merge/1.0.0 
npm http GET https://registry.npmjs.org/parseurl 
npm http GET https://registry.npmjs.org/debug/1.0.4 
npm http GET https://registry.npmjs.org/finalhandler/0.1.0 
npm http GET https://registry.npmjs.org/escape-html/1.0.1 
npm http GET https://registry.npmjs.org/ms/0.6.2 
npm http GET https://registry.npmjs.org/escape-html/1.0.1 
npm http GET https://registry.npmjs.org/ms/0.6.2 
npm http GET https://registry.npmjs.org/escape-html/1.0.1 
npm http GET https://registry.npmjs.org/ms/0.6.2 
[email protected] C:\Users\u166824\AppData\Roaming\npm\node_modules\connect 
├── [email protected] 
├── [email protected] 
├── [email protected] ([email protected]) 
└── [email protected] ([email protected]) 

C:\Program Files\nodejs> 

是我安裝Connect模塊的成功?我如何知道「連接」已正確安裝?

此外,當我嘗試啓動我的服務器,我收到以下錯誤:

C:\Program Files\nodejs>node server.js 

module.js:340 
    throw err; 
     ^
Error: Cannot find module 'connect' 
    at Function.Module._resolveFilename (module.js:338:15) 
    at Function.Module._load (module.js:280:25) 
    at Module.require (module.js:364:17) 
    at require (module.js:380:17) 
    at Object.<anonymous> (C:\Program Files\nodejs\server.js:1:77) 
    at Module._compile (module.js:456:26) 
    at Object.Module._extensions..js (module.js:474:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:312:12) 
    at Function.Module.runMain (module.js:497:10) 

而在我server.js的代碼如下:

var connect = require('connect'); 

connect.createServer(
    connect.static("../angularjs") 

).listen(5000); 

任何想法,爲什麼我無法連接?謝謝!

回答

0

嘗試驗證npm的環境變量是否設置正確? [您可以通過右鍵點擊我的計算機 - >屬性 - >高級系統設置選項卡進行檢查。

例如驅動器號:\ Users \用戶名\ AppData \漫遊\ NPM

1

你不能require()模塊,你已經安裝在故宮的-g標誌。刪除-g標誌:npm install connect-g用於安裝提供命令行工具的模塊,例如express-generator模塊。

此外,你真的不應該爲你的項目使用C:\Program Files\nodejs,因爲npm會將模塊安裝在你當前工作目錄的子目錄中......