0

So my project was all going well, it's all doing great, until I tried deploying it to Digital Ocean. The first landing page went well, but once I start to route, it gives out 404 error page instead

below is my webpack.config.js

module.exports = {
   context: __dirname,
   devtool: 'source-map',
   entry: ['./src/js/index.js','./src/sass/index.scss'],
   output: {
      path: path.resolve( __dirname, 'dist/' ),
      filename: 'main.js',
      publicPath: '/',
   },
   devServer: {
      historyApiFallback: true,
      contentBase: path.join(__dirname, 'dist'),
   },
   module: {
      rules: [
         {
            test: /.(js|jsx)$/,
            loader: 'babel-loader',
            exclude: [/node_modules/],
            options: {
                presets: ['@babel/react', "@babel/preset-env"]
            }
         },
         {
            test: /\.scss$/,
            use: ["style-loader", "css-loader", "sass-loader"]
        },
         {
            test: /\.css$/,
            use: ['style-loader', 'css-loader'],
         },
         {
            test: /\.(gif|png|jpe?g|svg|webp)$/i,
            use: [
               'file-loader',
               {
                  loader: 'image-webpack-loader',
                  options: {
                  bypassOnDebug: true, // webpack@1.x
                  disable: true, // webpack@2.x and newer
                  },
               },
            ],
         }
    ]
   },
   plugins: [
        new HtmlWebPackPlugin({
            template: path.resolve( __dirname, 'public/index.html' ),
            filename: 'index.html',
        }),
        new webpack.ProvidePlugin({
            "React": "react",
        }),
        new CopyWebpackPlugin({
            patterns: [
                { from: 'public/assets' }
            ]
        }),
   ]
};

I also tried using nginx server in Digital Ocean Droplet, below is my nginx file:

server {
    listen 80;
    listen [::]:80;
    
    root /var/www/html;
    index index.html index.html index.nginx-debian.html;

    server_name example.com;

    location / {
        try_files $uri /index.html;
    }
}

is this because of my webpack config? or is it something else?

  • there are few questions to ask. Does it conpile properly? are there any errors in the terminal? also can you confirm that you did not install the module as a development dependency via `npm i --save-dev`? Open `package` file and check. – Lith Mar 24 '21 at 10:55
  • all of the webpack and babel dependencies are saved in development – Justinus Amadia Wijaya Mar 24 '21 at 10:57
  • no error message when compiling, only warnings on size limit – Justinus Amadia Wijaya Mar 24 '21 at 10:58
  • Some dependencies such as babel, less, webpack, etc, should be installed as a developer dependency as they are not used in production. It is used during compiling, testing, etc - not for public. But react-router should NOT be installed as developer dependency. in production, all the modules that are installed in development mode are being, basically, ignored and the client never knows about them - to say it simply. If your `react-router` is installed as a developer dependency, reinstall it but this time not in dev mode. If its insatlled right - sorry for wasting your time. I dont know why – Lith Mar 24 '21 at 11:08
  • thank you for your advice, but my react-router is installed correctly, I really appreciate with the help anyway :) – Justinus Amadia Wijaya Mar 24 '21 at 11:09
  • Are you having this issue? [404 when trying to enter a react app route](https://stackoverflow.com/a/62050700/2873538) – Ajeet Shah Mar 24 '21 at 18:33
  • no, it's 404 from nginx, is it nginx problem? – Justinus Amadia Wijaya Mar 25 '21 at 01:53

0 Answers0