2017-06-28 25 views
0

當我運行NPM開始,但在Heroku的我不能做它的工作原理它的工作運行我的ReactJS的應用程序,我不能在Heroku的

2017-06-28T17:18:54.167693+00:00 app[web.1]: npm ERR! code ELIFECYCLE 
2017-06-28T17:18:54.167918+00:00 app[web.1]: npm ERR! errno ENOENT 
2017-06-28T17:18:54.168018+00:00 app[web.1]: npm ERR! syscall spawn 
2017-06-28T17:18:54.168132+00:00 app[web.1]: npm ERR! [email protected] start: `react-scripts start` 
2017-06-28T17:18:54.168203+00:00 app[web.1]: npm ERR! spawn ENOENT 
2017-06-28T17:18:54.168300+00:00 app[web.1]: npm ERR! 
2017-06-28T17:18:54.168387+00:00 app[web.1]: npm ERR! Failed at the [email protected] start script. 
2017-06-28T17:18:54.169487+00:00 app[web.1]: 
2017-06-28T17:18:54.168480+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 
2017-06-28T17:18:54.169649+00:00 app[web.1]: npm ERR! A complete log of this run can be found in: 
2017-06-28T17:18:54.169703+00:00 app[web.1]: npm ERR!  /app/.npm/_logs/2017-06-28T17_18_54_163Z-debug.log 

我的package.json,我看到了互聯網上,也許這裏是問題

<!-- language: lang-js --> 

    { 
     "name": "juego-cartas-reactjs", 
     "version": "0.1.0", 
     "main":"src/index.js", 
     "dependencies": { 
     "font-awesome": "^4.7.0", 
     "lodash.shuffle": "^4.2.0", 
     "react": "^15.6.1", 
     "react-dom": "^15.6.1", 
     "react-flipcard": "^0.2.1" 
     }, 
     "devDependencies": { 
     "react-scripts": "1.0.7" 
     }, 

     "scripts": { 
     "start": "react-scripts start", 
     "build": "react-scripts build", 
     "test": "react-scripts test --env=jsdom", 
     "eject": "react-scripts eject" 
     } 
    } 

我不知道自己還能做什麼,如果有人對此有所瞭解,幫助

+0

你在服務器上運行一個'NPM install'確保'反應,scripts'存在?看起來這就是它失敗的地方。 –

+0

你的意思是在我的heroku項目應用程序的控制檯? –

+0

是的!查看[他們的文檔](https://devcenter.heroku.com/articles/deploying-nodejs)獲取更多幫助。 –

回答

3

npm start只有 FO本地發展。你不應該在Heroku上使用它。

將創建React應用程序項目部署到Heroku follow Heroku's official guide to it

cd my-app 
git init 
heroku create -b https://github.com/mars/create-react-app-buildpack.git 
git add . 
git commit -m "react-create-app on Heroku" 
git push heroku master 
heroku open 

本文鏈接自您創建的應用程序附帶的Deployment section of the User Guide。我建議在那裏尋找可能的答案。

+0

這實際上不適用於我...應用程序仍然崩潰時,我嘗試在Heroku中運行它... –

1

我已經在heroku上成功上傳了一個create-react-app項目,並且沒有使用create-react-app buildpack。這裏是我的設置:

的package.json

//.. rest of package.json 

"dependencies": { 
    "express": "^4.14.0", 
    //.. rest of dependencies 
}, 

// need to define engines for heroku 
"engines": { 
    "node": "6.9.1", 
    "npm": "3.10.8" 
}, 
"scripts": { 
    "start": "node server.js #Production only!", 
    "postinstall": "npm run build", 
    "dev": "react-scripts start", 
    "build": "react-scripts build", 
    "test": "react-scripts test --env=jsdom", 
    "eject": "react-scripts eject" 
}, 

然後在項目的根目錄下,我創建了一個server.js,這僅僅是一個非常基本的表達應用。請注意,它使用構建文件夾而不是src文件夾。

const express = require('express'); 
const path = require('path'); 

const app = express(); 
const port = process.env.PORT || 3000; 

app.use(express.static(path.resolve(__dirname, 'build'))); 

app.get('*', (req, res) => { 
    res.sendFile(path.resolve(__dirname, 'build', 'index.html')); 
}); 

app.listen(port,() => { 
    console.info(`Server listening on port ${port}`); 
});