-
Notifications
You must be signed in to change notification settings - Fork 801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Full reload - Typescript + Babel #525
Comments
PS: I've also tried to disable the |
Hi, Just checking in with the exact same thing happening :( |
My local, minimal boilerplate contains a few visible changes from your current setup. I pulled config settings from the package.json "devDependencies": {
"awesome-typescript-loader": "3.1.2",
"babel-core": "^6.24.0",
"babel-loader": "6.4.1",
"babel-preset-es2015": "^6.24.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-0": "^6.22.0",
"react-hot-loader": "next",
"typescript": "2.2.2",
"webpack": "^2.3.2",
"webpack-dev-server": "^2.4.2"
}, webpack.config.js module.exports = {
entry: [
'babel-polyfill',
'react-hot-loader/patch',
'./src/index.tsx',
], ... module: {
rules: [
{
test: /\.tsx?$/,
use: [
'react-hot-loader/webpack', 'babel-loader', 'awesome-typescript-loader'
],
exclude: /node_modules/,
},
],
} tsconfig.json {
"compilerOptions": {
"module": "es6",
"target": "es6",
"lib": ["es6", "dom"],
"moduleResolution": "node",
"sourceMap": true,
"jsx": "preserve",
"rootDir": "src",
"allowSyntheticDefaultImports": true
},
"exclude": [
"node_modules"
]
} .babelrc {
"presets": [["es2015", { "modules": false }], "stage-0", "react"],
"plugins": ["react-hot-loader/babel"]
} |
@seamc so this setup is working for you? |
Yeah, here's a repo https://github.com/seamc/rhl-tsx-boilerplate |
@seamc thank u for the demo, do u think this problem can be solved without babel? |
finally i solved this https://github.com/DickyT/react_hot_loader_typescript_boilerplate |
@theduke I don't no why, but you must explicitly
I had the same problem. So I took react-hot-boilerplate and transformed it into typescript with minimal changes. Then hot-reloading stopped working anymore. Everything was fine in console, but changes weren't happening on page actually. |
Further to my previous comment I found the issue. In case of Typescript |
I added a test to reproduce the issue. |
@seamc way is working |
@dizel3d you saved my day! i don't know why it works, and i'm also wondering why the others don't need it indeed... |
@dizel3d import {App} from "./components/app/App"; |
One general workround: if (module.hot) {
// accept all changes, evaluate the whole js file
module.hot.accept();
render(Root);
} related #413 |
React Hot Loader v4 provides a good TypeScript support using Babel. I added an example with Typescript. |
I just had this problem, here's what I ad to use to fix it:
I found that just doing |
I experienced a similar issue where the hot reloading worked the first time after I started the dev server but every subsequent change triggered a full reload since the root component (index.tsx) wasn't accepted. When I switched to awesome-typescript-loader instead of ts-loader it started working with the exact same config. |
If you implement one of the fixes above and are still seeing full reloads React Router V3 may be the cause. |
I noticed the same issue as #525 (comment) - default exports are NOT registered (most of the time?) and because of that hot reloading for those components does not work. import * as React from 'react';
import { withStyles, WithStyles } from 'material-ui/styles';
const styles = {...};
export const MyComponent: React.SFC<WithStyles<'title'>> = () => <h1 className={classes.title}>Hello world!</h1>;
export default withStyles(styles)(MyComponent); However this one works: const MyStyledComponent = withStyles(styles)(MyComponent);
export default MyStyledComponent ; Maybe someone could a loader or something that detects those kind of e default export where an expression is used and rewrite them so they use a temporary const? EDIT: Also the tag "fixed in next" is wrong - I just tried upgrading and can confirm it does NOT work: var styles = function styles(theme) {
return {...};
};
exports.default = _styles_1.withStyles(styles)(exports.AppLayout);
(function () {
var reactHotLoader = __webpack_require__("./node_modules/react-hot-loader/patch.js").default;
var leaveModule = __webpack_require__("./node_modules/react-hot-loader/patch.js").leaveModule;
if (!reactHotLoader) {
return;
}
reactHotLoader.register(styles, "styles", "D:\\dev\\web\\haushalt-tracker\\src\\components\\core\\AppLayout.tsx");
leaveModule(module);
})(); The default export is not registered. EDIT 2: EDIT 3: So this issue needs to be fixed in v3 AND v4. |
Just in case someone has the same issue I was having. If you target ES6 with Typescript then apply the hot reload loader it won't work as if messes with the scope of the classes, not sure on the underlying issue.
Does not work.
Does work and retains the state. |
I have a very minimal setup with Webpack, tslint, Typescript and Babel.
On every save I get the output:
I noticed that the
module.hot.accept
callback is never invoked.I have followed the migration guide closely.
Running the dev server with:
webpack-dev-server --hot
.Any hints?
app.tsx:
App.tsx:
babelrc:
webpack.config.js:
The text was updated successfully, but these errors were encountered: