Does not inject new code
See original GitHub issueHello @AgentME could you please help me out a bit? I having hard times getting this thing to work.
It seems like updates being emitted early, but i don’t think so this is the problem because it never inject the code changed in the previous save.
Browser console:
[HMR] Websocket connection successful.
index.js:514 [HMR] Updated modules ["src/javascripts/main.js"]
index.js:514 [HMR] Updated modules ["src/javascripts/main.js"]
This is how my gulpfile looks:
let options = { debug: true };
if (config.isDev) _.extend(options, watchify.args);
let bundler = browserify(paths.src, options).plugin(hmr);
bundler.transform(babelify);
bundler.transform(hbsfy);
bundler.transform(envify);
if (config.isDev) {
bundler = watchify(bundler);
bundler.on('update', () => gulp.start('js'));
}
function bundle() {
return bundler.bundle()
.on('error', onError)
.pipe(source(config.js.bundleName))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.dest))
// .pipe(bs.stream({ once: true }));
}
gulp.task('js', preTasks, () => bundle());
Terminal:
[BS] Serving files from: public
GET / 200 10.957 ms - 486
GET /stylesheets/main.css 200 4.258 ms - 560724
GET /javascripts/main.js 200 1.663 ms - 1816775
GET /javascripts/main.js.map 200 3.722 ms - 2103596
19:34:59 GMT+0100 (CET) [HMR] User connected, syncing
[19:35:05] Starting 'js'...
19:35:06 GMT+0100 (CET) [HMR] Emitting updates
[19:35:07] Finished 'js' after 1.67 s
[19:35:12] Starting 'js'...
19:35:13 GMT+0100 (CET) [HMR] Emitting updates
[19:35:13] Finished 'js' after 1.22 s
I also use browsersync for server can that be a problem?
gulp.task('browser-sync', () => {
bs.init({
// A, if you don't have a backend api use the built in server
server: {
baseDir: 'public'
},
// B, if you got a backend api proxy the request to it
// proxy: 'some-vhost-of-existing-backend.api',
// custom middleware for mock api
middleware(req, res, next) {
require('../../api/api')(req, res, next);
},
// default port
port: config.isProd ? 8080 : 3000,
// disable notify popup
notify: false,
// do not open browser on start
open: false,
// disable UI completely
ui: false
});
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
5 ways to prevent code injection in JavaScript and Node.js
Learn some best practices for keeping your Node.js and JavaScript projects safe from code injection attacks.
Read more >Code Injection - OWASP Foundation
Code Injection is the general term for attack types which consist of injecting code that is then interpreted/executed by the application.
Read more >Code injection - Wikipedia
Code injection vulnerabilities occur when an application sends untrusted data to an interpreter. Injection flaws are most often found in SQL, LDAP, XPath,...
Read more >Using code injection - Squarespace Help Center
This is usually caused by injected code. To edit securely, click Disable Scripts in Preview at the bottom of your site.
Read more >Code Injection - an overview | ScienceDirect Topics
Code injection is a dangerous attack that exploits a bug caused by processing invalid data. Injection is used by an attacker to introduce...
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

Hello @AgentME, I am having this issue too. Also, I am using Browserify+Watchify+BrowserSync. I did use the module.hot.accept() in my custom HMR-like class. I am not using ud or React so I am just adding the following code at the end of my ES6 class.
I am also getting these outputs in the browser console:
However, it seems the JS code isn’t being re-inject in the <head/> tag just like WebPack does.
Any ideas on what’s causing this?
Hi @AgentME, did you yet came to write a little more about how to update already instantiated instances? I’m referring to your comment: “Or maybe you want to update already instantiated instances of a class. I plan to write a bit about this, but I’ve been delaying that until I polish up and fix a few bugs in Browserify-HMR”