javascript - Heroku : Error: ENOENT: no such file or directory, open '/app/build/index.html'? -
my directory :
i try depoly react project in heroku.
but, print error message.
it 'error: enoent: no such file or directory, open '/app/build/index.html'
my node.js server code
server/app.js:
import express 'express'; import morgan 'morgan'; import path 'path'; import loader './loader'; const app = express(); // server static file app.use(express.static(path.resolve(__dirname, '../build'))); app.use('/', loader); // exporting module export default app;
server/loader.js :
... export default (req, res) => { const filepath = path.resolve(__dirname, '../build', 'index.html'); fs.readfile(filepath, 'utf8', (err, htmldata)=>{ if (err) { console.error('read error', err) return res.status(404).end() } const context = {} const markup = rendertostring( <staticrouter location={req.url} context={context}> <app/> </staticrouter> ) if (context.url) { redirect(301, context.url) } else { const rendered = htmldata.replace('{{ssr}}', markup) res.send(rendered) } })
i think have no problems, when try connect, 'not found' page.
how can fix problem?
+edit:
my package.json:
... "engines": { "node": "6.11.1" }, "dependencies": { "axios": "^0.16.2", "express": "^4.15.4", "morgan": "^1.8.2", "react": "^15.6.1", "react-dom": "^15.6.1", "react-ga": "^2.2.0", "react-router": "^4.1.2", "react-router-dom": "^4.1.2", "react-scripts": "1.0.10", "semantic-ui-css": "^2.2.12", "semantic-ui-react": "^0.71.4" }, "scripts": { "start": "node_env=development ./node_modules/.bin/babel-node server", "start:server": "node_env=development babel-node server", "build": "react-scripts build", "test": "mocha test", "eject": "react-scripts eject" }, "devdependencies": { "babel-cli": "^6.26.0", "babel-core": "^6.26.0", "babel-plugin-transform-require-ignore": "^0.1.1", "babel-preset-env": "^1.6.0", "babel-preset-es2015": "^6.24.1", "babel-preset-react": "^6.24.1", "babel-preset-react-app": "^3.0.2", "babel-preset-stage-0": "^6.24.1", "chai": "^4.1.1", "mocha": "^3.5.0", "mz": "^2.6.0", "supertest": "^3.0.0", "supertest-as-promised": "^4.0.2" } }
you can use ci solution building , pushing heroku such circleci or travisci. i'm sure fresh build without errors.
pushing build
folder github fine well. i'm sure disagree reason i'm not aware of works fine.
Comments
Post a Comment