Skip to content

js and css files are not getting loaded in production environment. JS and CSS are again loading index.html  #4369

Closed

Description

@atulsingh0913

Is this a bug report?

Yes, i think it is , but i am really not sure about this.

Did you try recovering your dependencies?

Yes

(Write your answer here.)

Which terms did you search for in User Guide?

Troubleshooting , Deployment

(Write your answer here if relevant.)

Environment

node-v:

  1. node -v: v8.9.4
  2. npm -v: 5.6.0
  3. yarn --version (if you use Yarn):
  4. npm ls react-scripts (if you haven’t ejected):

Then, specify:

  1. Operating system: Linux
  2. Browser and version (if relevant): All

Steps to Reproduce

(Write your steps here:)

  1. When i am hoisting application in local , things are working fine , but when i try to host the same in production environment , nothing is getting loaded . It is coming to index.html , but the js and css are not getting loaded.
  2. Production URL is -> https://stg.abc.com/tools/forecaster.
    Local URL -> http://localhost:8081/tools/forecaster

routes.js

import React from 'react'
import {
  BrowserRouter as Router,
  Route
} from 'react-router-dom';
import login from './components/login';

const myTool = () => (
  <Router>
    <div>
      <Route exact path="/tools/forecaster" component={login}/>

      <Route exact path="/tools/forecaster_hs" component={login}/>

    </div>
  </Router>
)
export default myTool

server.js

const express = require("express");
const app = express();
const path = require('path');
const port = process.env.PORT || 8081 ;

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

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

app.listen(port);

Expected behaviour

The static assets should load from the build path

Actual behaviour

The static assets are also loading index.html file . It is not loading these files.

Activity

  1. miraage commented on Apr 27, 2018

    @miraage

    Did you provide PUBLIC_URL or homepage in the package.json? docs.

  2. gaearon commented on May 3, 2018

    @gaearon
    Contributor

    Closing per lack of response

  3. locked and limited conversation to collaborators on Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions