parcel: Hot Module Reloading not working, dev server not being updated.
đ bug report
I followed the steps exactly here: https://parceljs.org/getting_started.html
Making changes to either the js or html file does not cause any update to occur at localhost:1234 when parcel index.html
is run.
I also followed the react recipe verbatim with the same issue: http://blog.jakoblind.no/react-parcel/ Saving the file doesnât refresh the dev server.
đ Configuration (.babelrc, package.json, cli command)
package.json
{
"name": "parcel",
"version": "1.0.0",
"description": "",
"main": "index.html",
"scripts": {
"start": "parcel index.html"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.4.1",
"react-dom": "^16.4.1"
},
"devDependencies": {
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"parcel-bundler": "^1.9.2"
}
}
.babelrc
{
"presets": [
"env",
"react"
]
}
console command
npm start
also tried parcel serve index.html
and parcel index.html --no-cache
đ¤ Expected Behavior
Saved changes should cause the dev server to refresh
đŻ Current Behavior
Content builds correctly when the command is first run however, the dev server is not refreshed when a change is saved, so even refreshing the page doesnât do anything.
đŚ Context
I tried using global parcel-bundler as well as a local installation.
đť Code Sample
Followed the get started guide and react-recipe blog exactly.
index.html
<!DOCTYPE html>
<html>
<head>
<title>React starter app</title>
</head>
<body>
<div id="app"></div>
<script src="index.js"></script>
</body>
</html>
index.js
import React from "react";
import ReactDOM from "react-dom";
class HelloMessage extends React.Component {
render() {
return <div>Hlo{this.props.name + this.props.name}</div>;
}
}
var mountNode = document.getElementById("app");
ReactDOM.render(<HelloMessage name="Jane" />, mountNode);
đ Your Environment
Tried in chrome as well as firefox
Software | Version(s) |
---|---|
Parcel | 1.9.2 |
Node | 8.11.3 |
npm/Yarn | 5.6.0 |
Operating System | Mac |
Firefox Dev edition | 62.0b1 |
Chrome | 67.0.3396.87 |
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 5
- Comments: 77 (5 by maintainers)
I found this broke for me if i had a script tag like
But works if i load it as a module
It looks like if i have a non-module script parcel doesnât inject its bundle of hotreloading stuff
Thanks @Michael-N đ Removing the periods in the containing folder fixed this problem for me, I just replaced them with hyphens. Renamed folder from
hrafnkellbaldurs.github.io
tohrafnkellbaldurs-github-io
. I also noticed that it wasnât just the containing folder that I had to remove periods from. Any parent folders that had periods had to be renamed as well.I am using react / material ui for this project.
This issue has blocked me from adopting Parcel. I am back on Rollup until this issue is resolved.
@DeMoorJasper Can we re-open this issue? The presence of periods in any parent folder breaks
watch
like @hrafnkellbaldurs pointed out.Iâm having the same problem and this is like 5th time Iâm trying Parcel over last 6 months or so and I just canât get Parcel to refresh the page, it rebuilds but doesnât refresh. Iâm on Windows, using TypeScript and the issue persists no matter the browser (I tried Chrome, Firefox and Opera). Really annoying.
@DeMoorJasper Iâm using VS Code which doesnât have safe write functionality. https://github.com/Microsoft/vscode/issues/28927
I believe I have been having the same problem⌠Safe write was not the error for me. I can confirm what @samsch said
It also seems like once it goes away, it doesn't tend to come back in that project.
. However if I rename the containing folder, parcel will no longer detect watch changes, even after restarting the parcel build while the folder name change is in effect. I tried using the api to ensure the correct dir is passed and the problem above still persists. Deleting .cache was not enough to fix it for me. Any help is appreciated. Thanks!EDIT
Michael-N.github.io
. I removed the periods in the folder name and it all began working. Removing the periods fixed it for me.Ok, found my problem, possibly @j0hnm4r5 's as wellâŚ
Turns out when I was recreating my project I inadvertently named a folder "C"omponents instead of âcomponentsâ. I was using
import {Title} from 'components'
but theTitle.tsx
file lives in theComponents
folder. The part that really makes this challenging is that everything works correctly, parcel finds the file, loads it, renders it, no linting error, etc. The only thing that doesnât work is hot reloading.This seems like it should either not work at all (ie
Can't find dependency 'Title' in 'components'
error) or HMR should be case insenstive. Either way would have helped me pinpoint the problem.The inconsistent behavior between initial loading and HMR led me downgrading babel to earlier versions, stripping out dependencies, removing plugins etc from
.babelrc
just to happen to notice the capitol letter after hours of banging my head on the wall.I am experiencing hot reloading working exactly once, and then never again. It reloads after a single change, but then all following changes do not cause hot reload. I have no directories with periods. Deleting
.cache
anddist
do not work. Restarting did not work.Windows 10 Parcel version 1.10.3 WebStorm 2018.2 TypeScript
Iâve been seeing reports of this on Freenode, and had it happen a couple times myself. In particular, this bug chased away a user from Parcel entirely today. I think it happens on certain first runs. I was able to reproduce it once with their code, but not consistently. There is a problem here, so it would be great to re-open.
The specific code failed was
index.html
andsrc/app.js
with this content:index.html:
src/app.js:
I dropped those into a folder which had parcel install and ran it (but I think I may have tried to run it with the app.js file in root first?) and it reproduced, with changes to app.js not causing rebuilds, even after killing and restarting the parcel process (run with
npx parcel index.html
).It seems to have happened more when changing a script src is involved at some point. It also seems like once it goes away, it doesnât tend to come back in that project. Unfortunately, I wasnât able to get feedback from the user whether deleting .cache fixed it or not. Deleting the .cache folder doesnât not seem to be enough to get the issue to come back.
I tried the solutions mentioned here before i was able to fix this by making my script type=âmoduleâ then adding this code to it:
if (module.hot) { module.hot.accept(function () { location.reload(); }); }
Ok, if anyone else is using Windows + WSL and tearing their heart out because no matter what you do, HMR doesnât work⌠the problem is with WSL 2.
Currently, WSL 2 has a number of problems related to files crossing filesystem boundaries (i.e. if your project is actually under Windows but accessible to WSL under
/mnt/c/something...
.To work around the problem, you can convert your distro back to WSL 1. Open an Administrator command prompt and:
wsl -l
to list the distros you have.wsl --set-version DISTRO 1
, where DISTRO is the name of your distribution.wsl --shutdown
to restart the WSL service.After this, as if by magic, HMR works again. If anyone has further input on this and a better workaround, Iâm all ears.
If Hot Module Reloading is not working, the problem may relate to the periods (
.
) of the directories name. We can try to get rid of them.Consider changing the
import
statement from relative path to absolute path, and then changeing it back. This magically works for me.As per @tehfailsafe comment, having the name of the file and the import statement with the same letter capitalisation solved the issue for me.
E.g.: importing a component like this:
import Button from './button';
Where the actual folder is called /Button (notice the capital B), works on first run but it doesnât after saving the changes.
đSo making sure the name folder and import have exactly the same name with the same capital letters fixed this issue (for me).
This issue should be reopened⌠HMR not works on windows, since version 1.9.5 to latest 1.10.3.
This worked for me, hope works for another person with the issue from now
Was running into this problem on macOS with Visual Studio Code. Deleting
.cache
and.dist
folders didnât help and there were no files with dots when I ranpwd
in the terminal.Turns out parcel really doesnât like
document.addEventListener("DOMContentLoaded"
. Since this event is only triggered on the first load.So I removed the
DOMContentLoaded
callback and adjusted the code to work without it, then HMR came back!Old (Non Working) Setup
Working Setup
Hope that helps!
I think there are two overlapping issues here: the period-in-directory one, and the one @gitnix and I are having.
I have no folders with dots anywhere in their names, and Iâm getting super inconsistent reloading across my and my coworkersâ machines.
Anecdotally, I think it fixes itself if we delete the
dist
and.cache
folders and restart the server. Itâs happening so inconsistently that itâs hard to know for sure though.I have the same problem. I made a workaround, feel free to use it while itâs not fixed. Steps:
enableHotReload();
in your index.tsx just belowReactDOM.render();
and done.Same problem of HMR not updating. My solution is not enabling https on the dev server. When I do not use https, HMR works properly. When I run with
--https
it does not. When I again run, but without--https
it works again.So, HMR does not work with:
parcel src/index.html --out-dir=dev --https --open
HMR does works withparcel src/index.html --out-dir=dev --open
Parcel v1.11.0
Using different ports worked for me as described here: https://github.com/parcel-bundler/parcel/issues/6994
I ran into this problem and it was because I was trying to edit an HTML file without a JS import. I think this should work no matter if you have a JS src tag or not.
A discovery that I made was that Parcel HMR is case sensitive to imports. It is obviously a typo error by me, but it might help someone that is also having problems with HMR. I did not get any tsc or tslint errors in vscode and the code runs even though the filename is App.tsx. Changing the import of App to
import { App } from './App'
makes HMR work again.Main.tsx
App.tsx
Running parcel build is also case sensitive on Linux, so it will fail. Works on OSX.
Same problem, created a new project based off an old (fully HMR working) project. Super bare bones and minimal, but HMR only works on the top level of a react-router based project. Child routes simply wonât reload. Restarted, no periods, can open the other project and everything works perfectly, but not this one that is a copy of it⌠đŚ
Tried the above delete
dist
and.cache
, restart, no luck either.I am also experiencing this issue. Using VSCode (no safe-write). Donât have any odd folder names and 1.9.4 doesnât behave any differently.
Same problem but since 1.9.5⌠1.9.4 itâs ok!
So I have no clue what happened, but I was having the same issue with a separate project that uses create-react-app. Restarting my computer fixed the problem. đ¤ˇââď¸
For me on windows vsCode v1.84 and parcel v2.10.3 in year 2023 helped this:
.parcel-cache
folderReplying to https://github.com/parcel-bundler/parcel/issues/1591#issuecomment-1183536085 Keeping the Parcel project on the /home/userName path on WSL 2 also seems to solve the issue described by OP.
Hot reload issue solved for me after i added
type="module"
to my main .js file, now all changes to HTML and JS files are being reflected automatically. parcel -v 2.4.1Agree with @GeorgeFlorian, I am also working with Parcel^2.0.1. The changes sometimes donât reflect in the dist folder when the changes are made in other js files that are imported in the main js file. Can anyone please help with this issue? I tried moving all my files to another newly created folder and npm install on that. The problem remains the same.
I solved my issue like that too. I agree it should live reload even if only using html code.
Just to add a little to the body of knowledge here. It was case sensitivity on an import statement that broke it for me. A dumb typo on my part that wasted the good part of a morning!
@kennethkeim This is a very old issue. Can you please open a new issue more details? Including your code and the steps to reproduce this?
HMR refused to work after I removed my index.js file because I no longer needed it. I tried a lot of the things recommended in the comments but nothing worked. As soon as I added index.js back and imported it in index.html, it worked.
Iâm on a macbook with vscode and parcel 2
Why is this issue still closed?? HMR is one of the most important features of parcel, and a lot of people are experiencing random problems with super simple projects.
This sometimes happens when you have an import like
import MyModule from './Module.jsx
and then you decide to lowercase file name but forgot to change the import.I just start to try Parcel. With minimal setup it does not reload as you said, no file names with periods or any typos, just basic html. No reload after changing title below.
Does anyone elseâs issue resolve itself (at least temporarily) if you delete the folder where the compiled output is being put?Scratch that. On further investigation, itâs not resolved by blowing away the files â I believe it resolves itself for me as soon as the code successfully compiles again (that is, until all compilation errors are resolved, refreshing will continue to not work, but after a successful compilation, refreshing starts working again, at least temporarily).