node.js - Trying to deploy React Webpack app to Heroku, keep getting 'Uncaught Error: Cannot find module "./src/index.js"' error -
i'm trying deploy heroku, , build successful; however, blank screen , console has error:
'uncaught error: cannot find module "./src/index.js"'
also, while deploying, have following error:
error in loader /tmp/build_ad82f59a947c9639c358909b17671d27/node_modules/babel/index.js?{"presets":["react","es2015","stage-1"]} didn't return function
in local environment, have .env file private access tokens , use dotenv retrieve secret keys when make api call. have set config variables on heroku. when in heroku logs, error:
2016-09-12t22:16:15.191754+00:00 app[web.1]: > node server.js 2016-09-12t22:16:15.191755+00:00 app[web.1]: 2016-09-12t22:16:15.686543+00:00 app[web.1]: { [error: enoent: no such file or directory, open '.env'] errno: -2, code: 'enoent', syscall: 'open', path: '.env' }
here's webpack.config.js:
module.exports = { entry: [ './src/index.js' ], output: { path: __dirname, publicpath: '/', filename: 'bundle.js' }, module: { loaders: [{ exclude: /node_modules/, loader: 'babel', query: { presets: ['react', 'es2015', 'stage-1'] } }, { test: /\.jsx?$/, loaders: ['babel'], exclude: /node_modules/ }, { test: /\.css$/, loader: 'style-loader!css-loader' }, { test: /\.(png|jpg)$/, loader: 'url?limit=25000' }] }, resolve: { extensions: ['', '.js', '.jsx'] }, devserver: { historyapifallback: true, contentbase: './' } };
here's package.json:
"devdependencies": { "babel-core": "^6.2.1", "babel-loader": "^6.2.0", "babel-preset-es2015": "^6.1.18", "babel-preset-react": "^6.1.18", "chai": "^3.5.0", "chai-jquery": "^2.0.0", "enzyme": "^2.4.1", "jquery": "^2.2.1", "jsdom": "^8.1.0", "mocha": "^2.4.5", "react-addons-test-utils": "^0.14.7", "webpack-dev-server": "^1.14.0" }, "dependencies": { "axios": "^0.13.1", "babel-preset-stage-1": "^6.1.18", "body-parser": "^1.15.2", "dotenv": "^2.0.0", "express": "^4.14.0", "lodash": "^3.10.1", "material-ui": "^0.15.2", "react": "^15.3.0", "react-dom": "^15.0.0", "react-redux": "^4.0.0", "react-router": "^2.0.1", "react-tap-event-plugin": "^1.0.0", "react-tweet": "^1.0.22", "redux": "^3.0.4", "twitter": "^1.3.0", "webpack": "^1.12.9" } }
here server.js:
var express = require('express'); var bodyparser = require('body-parser'); var twitter = require('twitter'); var path = require('path'); var app = express(); var port = process.env.port || 3000; var dotenv = require('dotenv'); dotenv.config(); const api_twitter_url = 'https://api.twitter.com/1.1/search/tweets.json'; var client = new twitter({ consumer_key: process.env.consumer_key, consumer_secret: process.env.consumer_secret, access_token_key: process.env.access_token_key, access_token_secret: process.env.access_token_secret }); // configure express use body-parser middleware app.use(bodyparser.urlencoded({ extended: false, limit: '500mb' })); app.use(bodyparser.json({ limit: '500mb' })); // serve static files index.html, css etc app.use( express.static( __dirname ) ); app.get('*', (req, res) => { res.sendfile(path.resolve(__dirname), 'index.html'); }); app.post('/api/gettweets', function(req, res) { var params = { q: req.body.searchquery + '+everlane', filter: 'media' }; client.get(api_twitter_url, params, function(error, tweets, resp) { if (error) { console.log('error: ', error) } if (!error) { res.send(tweets); } }); }); app.listen(port, function() { console.log('\nproduction express server running @ localhost:' + port); });
Comments
Post a Comment