-
-
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
Source Maps in node_modules package #8071
Comments
@JeremyGrieshop - Are you running the just-released CRA/react-scripts 3.3 or 3.2? 3.3 has a fix (#7022 -- full disclosure it's my PR) that is a partial fix for sourcemap issues in CRA apps. Specifically, it fixes the case where node_modules dependencies don't have sourcemaps. For node_modules dependencies that do have sourcemaps, there's more fixing needed. #2355 is on the right track, but the current source-map-loader package is apparently not maintained and unfortunately it has serious bugs which are addressed in this fork: https://github.com/Volune/source-map-loader/tree/fixes which I've been using (via customize-cra) for 6+ months with great results. I've been planning a follow-up PR to #7022 which will fix #2355, but first I wanted to get some questions answered from sourcemap experts about how to handle relative paths from one node_modules dependency to another node_modules dependency. Also before adding source-map-loader to CRA, there needs to be a long-term supported home of source-map-loader because although @Volune's fork works well, it's not officially maintained either. Luckily it's only one relatively short file so hopefully finding a home won't be too hard. It may be short enough for the CRA maintainers to consider including it in CRA, but that seems like a last resort. |
I have not yet. I literally saw that release and note about 20 minutes after I posted this. I plan to try it out this weekend and find out, though!
Unfortunately, this is the boat I'm currently in. My node_module packages are my own that I generate source maps for, via direct babel compile.
I'm very curious about your findings here, as I also have the unique situation where my node_modules package also has a dependency on another of my node_modules packages, which in turn has its own source maps!
I'll be happy to try anything out if you need feedback or testing. Thanks for the reply! |
@JeremyGrieshop - thanks for the offer of help! I think at this point there are two blocking issues to getting this fixed:
If you can help resolve either of these issues, your help would be very welcome! |
Also, if you're looking for a workaround in the meantime, I use customize-cra to inject source-map-loader into my CRA config. Below is a simplified version of the const { override, useEslintRc, addWebpackModuleRule, addWebpackPlugin } = require('customize-cra');
const { produce } = require('immer');
const updateWebpackModuleRules = config => {
const rules = config.module.rules;
if (rules.length !== 3) {
throw new Error('Unexpected CRA config. Exiting.');
}
const newConfig = produce(config, cfg => {
const sourceMapLoader = {
enforce: 'pre',
exclude: /@babel(?:\/|\\{1,2})runtime/,
test: /\.(js|mjs|jsx|ts|tsx|css)$/,
use: 'source-map-loader',
};
const rules = cfg.module.rules;
rules.splice(1, 0, sourceMapLoader);
});
return newConfig;
};
const overrides = [updateWebpackModuleRules];
module.exports = override(...overrides); If you're not familiar with customize-cra, here's how to use the code above:
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test", |
@justingrant This workaround absolutely worked without any effort - thank you!!!! I can understand the longer-term dilemma of making it supportable by CRA. If everyone dumped all of their wishlist into CRA, it would probably look a lot like, well, webpack. As the React ecosystem grows, however, the trend of creating react component libraries will likely become more common place and I suspect more people will want the functionality of debugging them from larger projects / monorepo architecture. Even more so now that VS Code is growing in its user base. I hope to see something like this included out of the box. Again, if there's anything I can do to help, I'd be happy to do so in a way that I can. Thanks again for your help here, this will save me countless hours of console.log debugging lol. |
Hi @justingrant, is there a particular reason why you use volune/source-map-loader and not the normal source-map-loader module? |
Yep. The current release of source-map-loader only supports absolute paths in a sourcemap's You can read more details in @Volune's PR here: webpack-contrib/source-map-loader#75 Unfortunately, |
thanks mate, pretty useful. |
@justingrant is there a way to get it working using the customize-cra api addWebpackModuleRule? I'm trying to use this configuration but I keep getting errors:
and this is the error: |
@middiu - If I remember correctly, |
thanks again @justingrant. Your snippet of code was not working for me, but I managed to get it working in this way:
of course the part around devServer and HTTPS is irrelevant for this issue. Thanks a lot |
OK everyone, I opened PR #8227 to add source-map-loader to CRA. Please add your feedback and/or votes! |
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. Just waiting for a maintainer to review #8227 which should fix this issue. |
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. Just waiting for a maintainer to review #8227 which should fix this issue. |
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 a maintainer to review #8227. |
For what it's worth — I don't know much about source maps or webpack so take my message with a grain of salt —, but I've made the following changes so that sourcemap works in CRA in my lerna monorepo. As suggested, I've tweaked the config of CRA but using smart-source-map-loader which I believe fixes some issues of const enableWorkspaces = require('react-app-rewire-yarn-workspaces')
module.exports = function override(config, env) {
config.module.rules.splice(1, 0, {
enforce: 'pre',
exclude: /@babel(?:\/|\\{1,2})runtime/,
test: /\.(js|mjs|jsx|ts|tsx|css)$/,
use: 'smart-source-map-loader',
})
return enableWorkspaces(config, env)
} I've also added this line to the webpack config of other packages used by CRA, inspired by this webpack/webpack#3603 (comment) {
output: {
// ...
//fixes source maps
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
},
devtool: 'cheap-module-source-map',
// ...
} |
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 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. |
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. |
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! |
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. |
The stale bot is one of the best ways to disrespect the community. |
As of react-scripts@4.0.0, the |
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. |
The stale bot is one of the best ways to disrespect the community. |
On going for over a year now. Has anyone got any interest in fixing support for source-map from imported modules? |
So I also have this problem. I created a sample repo here https://github.com/vonkanehoffen/cra-monorepo-sourcemap-bug that demonstrates it if that helps any :-) ...I think this is the same issue anyway. Very interested to see if #8227 makes it in! :-D |
I haven't had much luck being able to debug/set breakpoints in source compiled with create-scripts and thought my use case may be somewhat unique, so I wanted to ask it here. If it's something I should take up with VSCode, I will, but I needed to start somewhere.
My setup is VS Code with an app created by create-react-app. I can debug it just fine, and I hit my breakpoints, as expected, so source maps are indeed working. However, I recently moved some of our components out into its own libraries, so they can be published separately and used by multiple apps. So, now they look like (I've simplified the example):
Now, I can only set breakpoints in lib/componentA.js instead of src/componentA.js (pre-compiled source). Is this something that I should be able to get working?
Any direction would be helpful. Thanks in advance!
Edit: perhaps it's related to #2355 ?
The text was updated successfully, but these errors were encountered: