-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
CRA's sourcemaps don't match code in node_modules, which breaks IDE debugging #6296
Comments
FWIW, I tested every possible value of webpack's devtool setting in https://webpack.js.org/configuration/devtool/. None of them worked. :-( Here's the process I used for testing on a CRA app:
|
@justingrant not sure if it will make a difference to this particular bug, but note that the config for webpack's sourcemap creation was recently changed. That change fixes a different sourcemap related bug (see #6074 (comment)); it might be worth seeing how it affects this one. |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
not stale |
@justingrant the "whitespace handling" is because the CRA webpack config runs node_modules through a limited babel transformation to support ES6 packages after long and concerted demand from users. The "bug" this issue relates to is actually another opinionated and deliberate design choice (#5096 by @Timer) which you can't get out of unless you fork or eject. FWIW I think that options like this should be controllable without an eject. To save you the hassle of finding it, this code is now here. |
To get this to work, you need to change two things. In the loader definition for node_modules change the value for Before the main loaders (around here) add the following: {
test: /\.m?js/,
enforce: 'pre',
use: ['source-map-loader'],
}, This is so that files in node_modules that have already been transpiled, and have source maps already, are picked up by webpack to show the original source. Remember to add |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue. |
PR #7022 is (hopefully) the solution for this issue. Please go over there for more info about the root cause and proposed solution for this problem. And while you're there, vote for it with a thumbs up! ;-) |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
not stale. still waiting for PR #7022 to get some attention. |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Not stale. Waiting for #7022. |
React source code inside sourcemaps generated by
create-react-app
adds many extra blank lines and extra indentation compared with React'snode_modules
source. Because line and column numbers don't match between source maps and actual source, debuggers like VSCode don't accurately set breakpoints inside React source and can't accurately step into React source. Debuggers like Chrome are not affected because they use the sitemap source (not the on-disk files) to set breakpoints.This issue is the cause of #6044 that @raiskila filed 6 weeks ago. I created a new issue with a new repro to simplify the repro case, to remove the need to install VSCode to reproduce the problem, and to clarify that all file-based debuggers will be affected (not just VSCode).
It's possible that the root cause of this problem might be webpack/webpack#8302, although I don't know enough about webpack to know for sure one way or the other. It's also possible that the problem is caused by
create-react-app
's webpack configuration. It's also possible that the problem might be in how React itself is transforming its source code before publishing generated source files likereact-dom.development.js
to NPM.Is this a bug report?
Yes
Did you try recovering your dependencies?
Yes. Well, really N/A because the repro starts with
npm install -g npm@latest
andnpx create-react-app
so there are no deps to recover!NPM version is the latest: 6.7.0
Which terms did you search for in User Guide?
sourcemap sourcemaps "source map" "source maps" mismatch whitespace line breakpoint
Environment
Environment Info:
Steps to Reproduce
1. Create a new app
2. Load the sourcemap and extract code from it
react-dom.developmment.js
source in the map by searching for "react-dom.development.js\n
" (without quotes) inside the sourcemap content. If it's not there, try http://localhost:3000/static/js/0.chunk.js.map instead./** @license
which should be right before the found content, copy 40-50 lines of code. Here's an example of what I copied:\n
with a newline and\"
with a regular single quote. You should end up with code like this:3. Compare the sourcemap code to actual source in
node_modules/react-dom/cjs/react-dom.development.js
:Expected Behavior
Source is the same, which is required for VS Code's debugger breakpoints and step-into to work properly.
Actual Behavior
The "sourcemap source" has many extra blank lines compared with the "node_modules source". As a result of these whitespace differences, VSCode breakpoints won't work and VSCode will set focus to the wrong code line when stepping into React's source code.
Also, the "sourcemap source" is indented differently from the "node_modules source". This breaks columnar breakpoints in VSCode.
Note that the Chrome debugger only uses the "sourcemap source" (and ignores the actual source files) so it's not affected by this problem by default. However, if you use a Chrome devtools workspace to actually load the on-disk source files, it's possible that Chrome debugging may break too.
Refer to #6044 for screenshots demonstrating the impact on VSCode users. This issue is narrowly defined to highlight the root cause of #6044 (the mismatch in whitespace between sourcemaps code and node_modules code) without requiring VSCode to reproduce the problem.
Reproducible Demo
Repro is trivial and the problem reproduces with every
create-react-app
project so I'm assuming that a hosted repro is not needed. If this is a bad assumption, let me know and I'll post a repro project.The text was updated successfully, but these errors were encountered: