Skip to content

Commit

Permalink
Add source-map-loader for debugging into original source of node_modu…
Browse files Browse the repository at this point in the history
…les libraries that contain sourcemaps (#8227)
  • Loading branch information
justingrant committed Jun 2, 2021
1 parent 0415189 commit 382ba21
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
9 changes: 8 additions & 1 deletion packages/react-scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,13 @@ module.exports = function (webpackEnv) {
rules: [
// Disable require.ensure as it's not a standard language feature.
{ parser: { requireEnsure: false } },
// Handle node_modules packages that contain sourcemaps
shouldUseSourceMap && {
enforce: 'pre',
exclude: /@babel(?:\/|\\{1,2})runtime/,
test: /\.(js|mjs|jsx|ts|tsx|css)$/,
use: 'source-map-loader',
},
{
// "oneOf" will traverse all following loaders until one will
// match the requirements. When no loader matches it will fall
Expand Down Expand Up @@ -605,7 +612,7 @@ module.exports = function (webpackEnv) {
// Make sure to add the new loader(s) before the "file" loader.
],
},
],
].filter(Boolean),
},
plugins: [
// Generates an `index.html` file with the <script> injected.
Expand Down
1 change: 1 addition & 0 deletions packages/react-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"resolve-url-loader": "^3.1.2",
"sass-loader": "^10.0.5",
"semver": "7.3.2",
"source-map-loader": "^1.1.2",
"style-loader": "1.3.0",
"terser-webpack-plugin": "4.2.3",
"ts-pnp": "1.2.0",
Expand Down
18 changes: 11 additions & 7 deletions packages/react-scripts/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,17 @@ function build(previousFileSizes) {
process.env.CI.toLowerCase() !== 'false') &&
messages.warnings.length
) {
console.log(
chalk.yellow(
'\nTreating warnings as errors because process.env.CI = true.\n' +
'Most CI servers set it automatically.\n'
)
);
return reject(new Error(messages.warnings.join('\n\n')));
// Ignore sourcemap warnings in CI builds. See #8227 for more info.
const filteredWarnings = messages.warnings.filter(w => !/Failed to parse source map/.test(w));
if (filteredWarnings.length) {
console.log(
chalk.yellow(
'\nTreating warnings as errors because process.env.CI = true.\n' +
'Most CI servers set it automatically.\n'
)
);
return reject(new Error(filteredWarnings.join('\n\n')));
}
}

const resolveArgs = {
Expand Down

0 comments on commit 382ba21

Please sign in to comment.