2014-04-24 34 views
0

首先,這裏是一個想經營我的server.js當CMD想出了錯誤:的Node.js應用程序檢查錯誤的目錄

C:\Users\Jacob\Desktop\setgame>node server.js 

fs.js:427 
    return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); 
       ^
Error: ENOENT, no such file or directory 'C:\Users\Jacob\Desktop\setgame\C:\User 
s\Jacob\Desktop\setgame\deps\JSON-js\json2.js' 
    at Object.fs.openSync (fs.js:427:18) 
    at Object.fs.readFileSync (fs.js:284:15) 
    at Build.add (C:\Users\Jacob\Desktop\setgame\node_modules\ams\lib\build.js:1 
32:34) 
    at buildStaticFiles (C:\Users\Jacob\Desktop\setgame\server.js:135:6) 
    at Object.<anonymous> (C:\Users\Jacob\Desktop\setgame\server.js:17:1) 
    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) 

我的話非常困惑。 我在Windows 8.1.1 x64上運行node.js 0.10.26。 任何建議來解決這個錯誤?

編輯:這裏是server.js文件:

var http = require('http') 
    , fs = require('fs') 
    , io = require('socket.io') 
    , connect = require('connect') 
    , gzip = require('gzippo') 
    , nowww = require('connect-no-www') 
    , ams = require('ams') 
    , Game = require('./game') 
    , server 
    , games = {} 
    , latestPublicGame 
    , clientDir = __dirname + '/client' 
    , publicDir = __dirname + '/public' 
    , depsDir = __dirname + '/deps' 
    , prod = process.env.NODE_ENV === 'production'; 

buildStaticFiles(); 

function niceifyURL(req, res, next){ 
    if (/^\/game\/public/.exec(req.url)) { 
    res.writeHead(302, { 
     'Location': '/game/#!/' + getLatestPublicGame().hash 
    }); 
    return res.end(); 
    } 
    if (/^\/game$/.exec(req.url)) { 
    res.writeHead(301, { 'Location': '/game/' }); 
    return res.end(); 
    } 
    if (/^\/game\//.exec(req.url)) { 
    req.url = '/game.html'; 
    } else if (/^\/about/.exec(req.url)) { 
    req.url = '/about.html'; 
    } else if (/^\/help/.exec(req.url)) { 
    req.url = '/help.html'; 
    } else if (/^\/?$/.exec(req.url)) { 
    req.url = '/index.html'; 
    } 
    return next(); 
} 

server = connect.createServer(
    connect.logger(':status :remote-addr :url in :response-timems') 
    , nowww() 
    , niceifyURL 
    , gzip.staticGzip(publicDir, { 
     matchType: /text|javascript/ 
     , maxAge: prod ? 86400000 : 0 
    }) 
    , gzip.staticGzip(publicDir + '/perm', { 
     matchType: /image|font/ 
     , maxAge: prod ? 604800000 : 0 
    }) 
); 

server.listen(prod ? 80 : 8000); 

io = io.listen(server); 
io.configure('production', function() { 
    io.enable('browser client minification'); // send minified client 
    io.enable('browser client etag');   // apply etag caching logic based on version number 
    io.enable('browser client gzip');   // gzip the file 
    io.set('log level', 1);     // reduce logging 
    io.set('transports', [      // enable all transports (optional if you want flashsocket) 
     'websocket' 
    , 'flashsocket' 
    , 'htmlfile' 
    , 'xhr-polling' 
    , 'jsonp-polling' 
    ]); 
}); 

function getUnusedHash() { 
    do { var hash = randString(4); } while (hash in games); 
    return hash; 
} 
function getGame(hash) { 
    if (hash && hash in games) return games[hash]; 
    hash = getUnusedHash(); 
    return (games[hash] = new Game(io, hash)); 
} 

function getLatestPublicGame() { 
    if (!latestPublicGame || 
    latestPublicGame.started || 
    !(latestPublicGame.hash in games)) 
    { 
    var hash = getUnusedHash(); 
    latestPublicGame = games[hash] = new Game(io, hash, 3); 
    } 
    return latestPublicGame; 
} 

io.sockets.on('connection', function(socket){ 
    var game = null; 
    socket.on('init', function(message){ 
    console.log('connecting socket ' + socket.id); 
    game = getGame(message.game); 
    game.registerClient(socket, message.sess); 
    (game.handleClientMessage('init', socket)).call(game, message); 
    if (message.game !== game.hash) socket.emit('setHash', game.hash); 
    }); 

    socket.on('disconnect', function() { 
    if (!game) return; 
    var hash = game.hash; 
    game.unregisterClient(socket, function gameOver() { 
     console.log('gameover called'); 
     delete games[hash]; 
    }); 
    game = null; 
    }); 
}); 

var CHARSET = ['A','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','T','V','W','X','Y','Z']; 

function randString(size) { 
    var ret = ""; 
    while (size-- > 0) { 
    ret += CHARSET[Math.floor(Math.random() * CHARSET.length)]; 
    } 
    return ret; 
} 

function buildStaticFiles() { 
    var options = { 
    uglifyjs: prod, 
    jstransport: false, 
    cssabspath: false, 
    cssdataimg: false, 
    texttransport: false 
    }; 
    ams.build 
    .create(publicDir) 
    .add(depsDir + '/JSON-js/json2.js') 
    .add(clientDir + '/util.js') 
    .add(depsDir + '/jquery-bbq/jquery.ba-bbq.js') 
    .add(depsDir + '/jquery.transform.js/jquery.transform.light.js') 
    .add(clientDir + '/client.js') 
    .combine({js: 'client.js'}) 
    .process(options) 
    .write(publicDir) 
    .end(); 
    ams.build 
    .create(publicDir) 
    .add(clientDir + '/style.css') 
    .add(depsDir + '/headjs/src/load.js') 
    .process(options) 
    .write(publicDir) 
    .end() 
} 
+0

您可以從堆棧跟蹤中顯示的文件中發佈相關代碼嗎? – mscdex

+0

@mscdex我剛剛用server.js代碼編輯了這個問題。 – user3546401

回答

0

你的問題是這樣的:

, publicDir = __dirname + '/public' 
, depsDir = __dirname + '/deps' 

__dirname是絕對目錄路徑當前的腳本文件。所以這就是爲什麼你在錯誤信息中看到雙重路徑的原因。我假定當你做ams.build.create(publicDir)時,它設置了基本目錄和所有你認爲是相對於那個基本目錄(publicDir)的路徑.add()

因此,請嘗試將depsDirclientDir分別改爲'deps''client'

相關問題