question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Double reload because sourceURL is added to webpack watched files

See original GitHub issue
  • Operating System: macOS
  • Node Version: any
  • NPM Version: any
  • webpack Version: 5.11.1
  • source-map-loader Version: 2.0.0

Expected Behavior

Source files not added to webpack’s dependencies

Actual Behavior

Source files are added

My question

I am using react-refresh and HMR and noticed that my code reloads twice, I am using typescript seperately from webpack, and use tsc --watch in the background which compiles typescript to JS (and also generated the sourcemaps).

In another process, I have a very simple webpack config with a react refresh plugin and source-map-loader with the entry point pointing to the (typescript) compiled index.js file.

Now, I found that source-map-loader adds the source files (e.g. .tsx and .ts files) to webpack’s dependencies (and thus they are watched as well). Now, when I change a source file, webpack watch triggers, and when the typescript compiler finishes, webpack is triggered again because the compiled file is (naturally) in webpacks dependencies as well.

I wonder what can be done to improve this situation, perhaps we should add an option to this plugin to not add the source files as a dependency? I also wonder what the actual use case of adding the sourceURL as a dependency is.

Hope anyone can show me the light =)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Jan 21, 2021

I think we need document it here

0reactions
davidclark87commented, Sep 3, 2021

I hit the same issue as @vespakoen described. My app imports some JS files which have sourcemaps referencing TS files. When using source-map-loader, webpack watches the *.ts files and recompiles if I modify them. Setting watchOptions.ignored is a good workaround. But it seems odd to me that webpack is trying to watch the TS files in the first place - those TS files are not being imported anywhere in the app, so I would not expect webpack to recompile when they change. I’d expect it only to recompile if the JS file changes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack-dev-server compiles files but does not refresh or ...
js file I set the entry, output, and devServer settings as well as add a loader to look for changes in .vue files:...
Read more >
Hot Module Replacement - webpack
Hot Module Replacement (or HMR) is one of the most useful features offered by webpack. It allows all kinds of modules to be...
Read more >
webpack-dev-server
It'll watch your source files for changes and when changes are made the bundle will be recompiled. This modified bundle is served from...
Read more >
Why webpack-dev-server Live-Reload Is Not Working - Medium
When I modify javascript files, I have to manually run Webpack CLI to ... which should be appended to the webpack-dev-pack project url...
Read more >
Basic Features: Fast Refresh - Next.js
If you edit a file that only exports React component(s), Fast Refresh will update the code only for that file, and re-render your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found