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

HMR Not Working With Typescript Commonjs Modules #5189

Closed
pixelshaded opened this Issue Jun 29, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@pixelshaded

pixelshaded commented Jun 29, 2017

Typescript: 2.3.4
Webpack: 2.6.1
React: 15.6.1
React-hot-loader: 3.0.0-beta.6

Compiler Options:

"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"rootDir": "src",
"outDir": "dist",
"sourceMap": true,
"lib": ["es2015", "dom"],
"jsx": "react",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"suppressImplicitAnyIndexErrors": true,

We were using babel with flow and recently converted over to Typescript. The ts config uses module commonjs even though we are running the js in the browser (we were doing this because a few libs exported non-module objects). We noticed that HMR wasn't working. The browser is getting HMR data like the updated file etc, but nothing actually changes on the page. As soon as we use es2015 instead (along with allowSyntheticDefaultImports because of the non-modules), HMR works again. Is this to be expected? Does HMR not work with commonjs modules?

@Kovensky

This comment has been minimized.

Show comment
Hide comment
@Kovensky

Kovensky Jun 30, 2017

Collaborator

HMR works with commonjs iff you use commonjs directly.

You need to write accept callbacks that call require in them to be able to receive the newly evaluated code, and you have to update the variables where you saved the result of the first require so you can't use const requires. Only ES2015 modules have live bindings that are updated just by accepting the module.

Collaborator

Kovensky commented Jun 30, 2017

HMR works with commonjs iff you use commonjs directly.

You need to write accept callbacks that call require in them to be able to receive the newly evaluated code, and you have to update the variables where you saved the result of the first require so you can't use const requires. Only ES2015 modules have live bindings that are updated just by accepting the module.

@sokra

This comment has been minimized.

Show comment
Hide comment
@sokra

sokra Jul 4, 2017

Member

It looks like you just deleted our lovely crafted issue template. It was there for good reasons. Please help us solving your issue by answering the questions asked in this template. I'm closing this. Please open a new issue with filled issue template. Also make sure your issue is not a question. Questions should be posted on Stack Overflow.

Member

sokra commented Jul 4, 2017

It looks like you just deleted our lovely crafted issue template. It was there for good reasons. Please help us solving your issue by answering the questions asked in this template. I'm closing this. Please open a new issue with filled issue template. Also make sure your issue is not a question. Questions should be posted on Stack Overflow.

@sokra sokra closed this Jul 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment