0

I am creating a reactjs app and everything works fine on localhost. Things gets really problematic when I deployed the app to the hosting service.

I Have a ./reducers folder in my project which contains all of my reducers. the project structure is this:

  • App
  • ---reducers
  • ---store.js

now the problem is that webpack is unable to solve the import reducers from './reducers' on my store.js here is my full store.code:

import {applyMiddleware, createStore} from 'redux';

import logger from 'redux-logger';
import thunk from 'redux-thunk';
import promise from 'redux-promise-middleware';

import reducer from './reducers';

const middleware = applyMiddleware(promise(), thunk, logger())
  
export default createStore(reducer, middleware)

and here is my webpack config:

var path = require('path');
var webpack = require('webpack');

module.exports = {
	entry: './main.js',
	output:{
		path: __dirname,
		filename: 'index.js',
		publicPath: '/'
	},
	devServer:{
		inline: true,
		port: 1515,
		historyApiFallback: true
	},
	module:{
		loaders:[
		{
			test: /\.js?$/,
			exclude: /node_modules/,
			loader: 'babel-loader',
			query:{
				presets: ['react', 'es2015'],
				plugins: ['react-html-attrs', 'transform-object-rest-spread']
			}
		}
		]
	}
}

and here's the error from my hosting server:

enter image description here

I'm really sorry for the ultra long post, I've been googling around and haven't found an answer that i can understand..deploying reactjs app and webpack is something new for me

2
  • 1
    You're not trying to run Webpack's dev server on your proper web hosting environment, are you? If so - don't, you should be using a proper server and just deploying the final build from Webpack to it. Commented Mar 24, 2017 at 15:54
  • @JoeClay that is exactly what i'm trying to do... it does have a node js support if that is what's required for a proper server.. and what i did is that I run my webpack command on the server. I've been searching the web on how to build react webpack production and i didnt find any post that I can understand..I also tried using webpack -p on my local env and it yields nothing.. Commented Mar 25, 2017 at 2:14

2 Answers 2

1

Okay so after trying to digest every information that I got regarding this matter, I finally understand on how to deploy webpack project..

As mentioned by @JoeClay, I Should just deploy the final build from Webpack which is contrary to what I did. What I did is that I uploaded the whole project file into the hosting server and tried to run the webpack from there. I treated the production phase just like the local development phase which is not right.

After looking for so many information on the net on how to build a Webpack project I finally realized that this whole time I've got the build file with me. If we look back into my Webpack.config.js

module.exports = {
	entry: './main.js',
	output:{
		path: __dirname,
		filename: 'index.js',
		publicPath: '/'
	},
	devServer:{
		inline: true,
		port: 1515,
		historyApiFallback: true
	},
	module:{
		loaders:[
		{
			test: /\.js?$/,
			exclude: /node_modules/,
			loader: 'babel-loader',
			query:{
				presets: ['react', 'es2015'],
				plugins: ['react-html-attrs', 'transform-object-rest-spread']
			}
		}
		]
	}
}

We can see that in the output I have a filename of 'index.js' and every time I did things like npm start, It produces the 'index.js' on the directory. So it's always been there, I've just never paid much attention to it.

What I did next is easy, I go to my hosting server and upload my Index.html along with my CSS, JS and 'index.js' file and voila! It Works! But there is one problem that I haven't solve..Somehow after I Uploaded the file, inside my index.html file the <script src="index.js"></script> got commented out..I'd be so grateful if someone could give me an insight on this.

Hopefully this thread can help newbie webpack users like me and can help them deploy to hosting other than heroku or digitalocean. And thanks everyone who has spend their time answering my question

Sign up to request clarification or add additional context in comments.

1 Comment

I'm glad I could point you in the right direction :) I think a lot of people get confused about what role the Webpack dev server plays - hopefully your write-up will help other people who are having the same issue!
0

The problem is your reducers import is not found. You need to check your path relative to where your store is located.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.