2016-06-12 7 views
2

Node.JSのアプリケーションでPassportを使用した認証に関するチュートリアルをいくつか実行しようとしていて、npmを使用してNodeJSアプリケーションのトラブルシューティングを行う方法がわかりません。 debug.log私はAngularJS側で一般的です。特に、私は次のような問題を抱えています。誰かが私に問題の原因を教えてもらえますか?必要に応じて、関連するコードを追加で投稿することができます。npm-debug.logの読み方(Node.JSアプリケーションのトラブルシューティング)

NPM-debug.logに

0 info it worked if it ends with ok 
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ] 
2 info using [email protected] 
3 info using [email protected] 
4 verbose run-script [ 'prestart', 'start', 'poststart' ] 
5 info lifecycle [email protected]~prestart: [email protected] 
6 silly lifecycle [email protected]~prestart: no script for prestart, continuing 
7 info lifecycle [email protected]~start: [email protected] 
8 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true 
9 verbose lifecycle [email protected]~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/selfishman/www/sites/Playground/passport-local/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin 
10 verbose lifecycle [email protected]~start: CWD: /Users/selfishman/www/sites/Playground/passport-local 
11 silly lifecycle [email protected]~start: Args: [ '-c', 'node ./bin/www' ] 
12 silly lifecycle [email protected]~start: Returned: code: 1 signal: null 
13 info lifecycle [email protected]~start: Failed to exec start script 
14 verbose stack Error: [email protected] start: `node ./bin/www` 
14 verbose stack Exit status 1 
14 verbose stack  at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:232:16) 
14 verbose stack  at emitTwo (events.js:87:13) 
14 verbose stack  at EventEmitter.emit (events.js:172:7) 
14 verbose stack  at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14) 
14 verbose stack  at emitTwo (events.js:87:13) 
14 verbose stack  at ChildProcess.emit (events.js:172:7) 
14 verbose stack  at maybeClose (internal/child_process.js:818:16) 
14 verbose stack  at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5) 
15 verbose pkgid [email protected] 
16 verbose cwd /Users/selfishman/www/sites/Playground/passport-local 
17 error Darwin 14.5.0 
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "start" 
19 error node v5.1.0 
20 error npm v3.5.0 
21 error code ELIFECYCLE 
22 error [email protected] start: `node ./bin/www` 
22 error Exit status 1 
23 error Failed at the [email protected] start script 'node ./bin/www'. 
23 error Make sure you have the latest version of node.js and npm installed. 
23 error If you do, this is most likely a problem with the passport-local package, 
23 error not with npm itself. 
23 error Tell the author that this fails on your system: 
23 error  node ./bin/www 
23 error You can get their info via: 
23 error  npm owner ls passport-local 
23 error There is likely additional logging output above. 
24 verbose exit [ 1, true ] 

app.js

var express = require('express'); 
var path = require('path'); 
var favicon = require('serve-favicon'); 
var logger = require('morgan'); 
var cookieParser = require('cookie-parser'); 
var bodyParser = require('body-parser'); 
var mongoose = require('mongoose'); 
var passport = require('passport'); 
var LocalStrategy = require('passport-local').Strategy; 

var routes = require('./routes/index'); 
var users = require('./routes/users'); 

var app = express(); 

// view engine setup 
app.set('views', path.join(__dirname, 'views')); 
app.set('view engine', 'jade'); 

// uncomment after placing your favicon in /public 
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); 
app.use(logger('dev')); 
app.use(bodyParser.json()); 
app.use(bodyParser.urlencoded({ extended: false })); 
app.use(cookieParser()); 

app.use(require('express-session')({ 
    secret : 'keyboard cat', 
    resave : false, 
    saveUninitialized: false 
})); 
app.use(passport.initialize()); 
app.use(passport.session()); 

app.use(express.static(path.join(__dirname, 'public'))); 

app.use('/', routes); 

//passport config 
var Account = require('./models/account'); 
passport.use(new LocalStrategy(Account.authenticate())); 
passport.serializeUser(Account.serializeUser()); 
passport.desirializeUser(Account.deserializeUser()); 

//mongoose 
mongoose.connect('mongodb://localhost/passport_local_mongoose_express4'); 

// catch 404 and forward to error handler 
app.use(function(req, res, next) { 
    var err = new Error('Not Found'); 
    err.status = 404; 
    next(err); 
}); 

// error handlers 

// development error handler 
// will print stacktrace 
if (app.get('env') === 'development') { 
    app.use(function(err, req, res, next) { 
    res.status(err.status || 500); 
    res.render('error', { 
     message: err.message, 
     error: err 
    }); 
    }); 
} 

// production error handler 
// no stacktraces leaked to user 
app.use(function(err, req, res, next) { 
    res.status(err.status || 500); 
    res.render('error', { 
    message: err.message, 
    error: {} 
    }); 
}); 


module.exports = app; 

package.json

{ 
    "name": "passport-local", 
    "version": "0.0.0", 
    "private": true, 
    "scripts": { 
    "start": "node ./bin/www" 
    }, 
    "dependencies": { 
    "body-parser": "^1.13.2", 
    "chai": "~1.8.1", 
    "cookie-parser": "^1.3.5", 
    "debug": "^2.1.1", 
    "express": "^4.13.1", 
    "express-session": "^1.10.1", 
    "jade": "^1.11.0", 
    "mocha": "~1.14.0", 
    "mongodb": "^2.1.18", 
    "mongoose": "^3.8.22", 
    "morgan": "^1.6.1", 
    "passport": "^0.2.1", 
    "passport-local": "^1.0.0", 
    "passport-local-mongoose": "^1.0.0", 
    "serve-favicon": "^2.2.0", 
    "should": "~2.1.0" 
    } 
} 
+1

あなたのプロジェクトは、あなたが含めるべき依存関係と同じ名前ですか? – Claies

+0

はい。それは問題だろうか?私が言ったように、私はこのチュートリアルに従っています:http://www.bogotobogo.com/MEAN-Stack/MEAN-Stack-MongoDB-ExpressJS-AngularJS-NodeJS-Authentication-Passport-App.php – MadPhysicist

+0

私はよく分かりませんそれは問題であるかどうかは分かりませんが、問題がプロジェクトや依存関係にあるかどうかは明らかではないので、ログファイルの解析はちょっと難しくなります。 – Claies

答えて

4

短い答え:この問題は、NPMとは何の関係もありません。アプリケーションに例外をスローするバグがあります。

node ./bin/www 

のようにアプリケーションを起動すると、npmの干渉なしにコンソール上のスタックトレースで例外が表示されます。

長い答え:上記の結論に来てのファイルを読んでみましょう:

npm-debug.log ---ライン1:

verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ] 

これはあなただけでnpm startと呼ばれることを教えてくれる。あなたはおそらく既にそれを知っていたでしょう。

package.jsonスクリプト:

"start": "node ./bin/www" 

これはnpmnode ./bin/www

npm-debug.logライン14を呼び出すが、何もなかったことを示しています:

14 verbose stack Error: [email protected] start: `node ./bin/www` 
14 verbose stack Exit status 1 
14 verbose stack  at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:232:16) 
14 verbose stack  at emitTwo (events.js:87:13) 
14 verbose stack  at EventEmitter.emit (events.js:172:7) 
14 verbose stack  at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14) 
14 verbose stack  at emitTwo (events.js:87:13) 
14 verbose stack  at ChildProcess.emit (events.js:172:7) 
14 verbose stack  at maybeClose (internal/child_process.js:818:16) 
14 verbose stack  at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5) 

これはあなたのスタックトレースの一部です。 npmなしでアプリケーションを呼び出すと、同様の出力が得られます。

私はここからあなたのプログラムをデバッグするのに十分な情報がありません---しかし、あなたのアプリのどこかに投げられた通常の例外で、npmに関係するものではないことを知ってほしいと思います。

関連する問題