Components in subdirectory doesn't reload
See original GitHub issueNot sure why, I trimmed this down to the smallest possible app:
public/app/js/index.js
import React from 'react';
import App from './App';
import AppBis from './Components/App';
React.render(<div><App /><AppBis /></div>, document.getElementById('app'));
public/app/js/App.js
import React, { Component } from 'react';
export default class App extends Component {
render() {
return <h1>Hello, world.</h1>;
}
}
public/app/js/Components/App.js
import React, { Component } from 'react';
export default class App extends Component {
render() {
return <h1>Hello, world.</h1>;
}
}
Modifying js/App.js triggers RHL fine, but modifying js/Components/App.js doesn’t do anything. Nothing at all in the console, no polling, nothing.
Webpack config:
var path = require('path');
var webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'webpack/hot/only-dev-server',
'./public/assets/js'
],
output: {
path: path.join(__dirname, 'public/builds'),
filename: 'bundle.js',
publicPath: '/builds/'
},
devServer: {
contentBase: __dirname + '/public',
hot: true,
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [{
test: /\.jsx?$/,
loaders: ['react-hot', 'babel'],
include: path.join(__dirname, 'public/assets/js')
}]
}
};
public/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Budger</title>
</head>
<body>
<div id="app"></div>
<script src="builds/bundle.js"></script>
</body>
</html>
Am I doing something wrong here? I checked Troubleshooting and everything but nothing that fixed it. This is pretty much straight up the example from react-hot-boilerplate so I don’t see where I could have gone wrong. I tried using a node server instead of Webpack’s devServer option in the config, but same thing.
Issue Analytics
- State:
- Created 8 years ago
- Comments:5
Top Results From Across the Web
Not able to load React Components from a subdirectory in a ...
I created a directory called "components" under ...
Read more >Deploying React (Router) app to the subfolder on server
First, we need to update our routes to include full absolute path to the subfolder. Using React Router's basename #. As Davis Cabral...
Read more >How to deploy a React app to a subdirectory | by Scott Vinkle
Set the basename. Setting the basename attribute on the <Router /> component tells React Router that the app will be served from a...
Read more >An elegant solution of deploying React app into a subdirectory
The reason for that is the path: React still tries to load its resources and assets from the root folder without accounting for...
Read more >Assembly Load Options; Part Left Unloaded
One solution is to use the "from search folders" load option. You can specify which folders you want to search and in what...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Oh for christ’s sake. Ok I found the issue, I spent hours changing my codebase, my Webpack config, my folder structure, etc. And it was a goddamn casing issue. My folder was named
assets/js/componentsinstead ofassets/js/Componentswhich was ok to JS but not to RHL (or Webpack dev server, don’t know).Troubleshooting mentioned this:
So I checked all my files, but not my folders. I’m an idiot.
I updated my folder to match the casing in my imports. You can install this plugin to help you and prevent further similar errors.