2016-04-30 127 views
0

我克隆回購解析服務器從parse-server-example並添加運行蒙戈DB也通過npm install安裝的NodeJS pacakge,但是當我想用npm start打印這個錯誤在終端上運行的應用程序!解析服務器克隆安裝

我該如何解決這個問題?它是關於nodejs版本還是什麼? enter image description here

這裏是我的index.js文件:

// Example express application adding the parse-server module to expose Parse 
 
// compatible API routes. 
 

 
var express = require('express'); 
 
var ParseServer = require('parse-server').ParseServer; 
 
var path = require('path'); 
 

 
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI; 
 

 

 
var api = new ParseServer({ 
 
    databaseURI: databaseUri || 'mongodb://localhost:27017/dev', 
 
    cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', 
 
    appId: process.env.APP_ID || 'app', 
 
    masterKey: process.env.MASTER_KEY || 'master', //Add your master key here. Keep it secret! 
 
    serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed 
 
    liveQuery: { 
 
    classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions 
 
    } 
 
}); 
 
// Client-keys like the javascript key or the .NET key are not necessary with parse-server 
 
// If you wish you require them, you can set them as options in the initialization above: 
 
// javascriptKey, restAPIKey, dotNetKey, clientKey 
 

 
var app = express(); 
 

 
// Serve static assets from the /public folder 
 
app.use('/public', express.static(path.join(__dirname, '/public'))); 
 

 
// Serve the Parse API on the /parse URL prefix 
 
var mountPath = process.env.PARSE_MOUNT || '/parse'; 
 
app.use(mountPath, api); 
 

 
// Parse Server plays nicely with the rest of your web routes 
 
app.get('/', function(req, res) { 
 
    res.status(200).send('Make sure to star the parse-server repo on GitHub!'); 
 
}); 
 

 
// There will be a test page available on the /test path of your server url 
 
// Remove this before launching your app 
 
app.get('/test', function(req, res) { 
 
    res.sendFile(path.join(__dirname, '/public/test.html')); 
 
}); 
 

 
var port = process.env.PORT || 1337; 
 
var httpServer = require('http').createServer(app); 
 
httpServer.listen(port, function() { 
 
    console.log('parse-server-example running on port ' + port + '.'); 
 
}); 
 

 
// This will enable the Live Query real-time server 
 
ParseServer.createLiveQueryServer(httpServer);

而且通過安裝babel-cli和運行表明我:

/Users/sajad/Sites/parse/node_modules/parse-server/node_modules/babel-polyfill/lib/index.js:14 
 
    throw new Error("only one instance of babel-polyfill is allowed"); 
 
     ^
 
Error: only one instance of babel-polyfill is allowed 
 
    at Object.<anonymous> (/Users/sajad/Sites/parse/node_modules/parse-server/node_modules/babel-polyfill/lib/index.js:14:9) 
 
    at Module._compile (module.js:460:26) 
 
    at Module._extensions..js (module.js:478:10) 
 
    at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:134:7) 
 
    at Module.load (module.js:355:32) 
 
    at Function.Module._load (module.js:310:12) 
 
    at Module.require (module.js:365:17) 
 
    at require (module.js:384:17) 
 
    at Object.<anonymous> (/Users/sajad/Sites/parse/node_modules/parse-server/lib/ParseServer.js:9:1) 
 
    at Module._compile (module.js:460:26)

回答

0

這是因爲這個模塊(或者更準確地說,您的模塊的依賴關係)正在使用您的節點版本(v0.12)中不可用的const關鍵字。對const關鍵字的全面支持出現在剛剛在本週抵達的節點v6中。

另外,您可以transpile使用babel

項目如果用巴貝爾路線走,你可以做你的項目的根文件夾下面

npm install -g babel-cli 
babel-node index.js 

關於如何使用巴貝爾更多信息,請參閱babel usage page正確。

編輯:在你提供的文檔中,它明確告訴你至少必須有節點v4.3,並且你應該用命令「npm start」來運行該項目。所以我猜這個項目已經有了babel,你只是錯誤地運行它,並且使用了不正確的節點版本。

+0

您是否嘗試使用節點4.3並且沒有使用babel運行? – grimurd