Skip to content

Commit 148ca9d

Browse files
justingrantsumanthratna
authored andcommitted
Add source-map-loader for debugging into original source of node_modules libraries that contain sourcemaps (facebook#8227)
1 parent 30845c8 commit 148ca9d

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

packages/react-scripts/config/webpack.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,13 @@ module.exports = function (webpackEnv) {
385385
rules: [
386386
// Disable require.ensure as it's not a standard language feature.
387387
{ parser: { requireEnsure: false } },
388+
// Handle node_modules packages that contain sourcemaps
389+
shouldUseSourceMap && {
390+
enforce: 'pre',
391+
exclude: /@babel(?:\/|\\{1,2})runtime/,
392+
test: /\.(js|mjs|jsx|ts|tsx|css)$/,
393+
use: 'source-map-loader',
394+
},
388395
{
389396
// "oneOf" will traverse all following loaders until one will
390397
// match the requirements. When no loader matches it will fall
@@ -616,7 +623,7 @@ module.exports = function (webpackEnv) {
616623
// Make sure to add the new loader(s) before the "file" loader.
617624
],
618625
},
619-
],
626+
].filter(Boolean),
620627
},
621628
plugins: [
622629
// Generates an `index.html` file with the <script> injected.

packages/react-scripts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"resolve-url-loader": "^3.1.2",
8585
"sass-loader": "^10.0.5",
8686
"semver": "7.3.2",
87+
"source-map-loader": "^1.1.2",
8788
"style-loader": "1.3.0",
8889
"terser-webpack-plugin": "4.2.3",
8990
"ts-pnp": "1.2.0",

packages/react-scripts/scripts/build.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,17 @@ function build(previousFileSizes) {
193193
process.env.CI.toLowerCase() !== 'false') &&
194194
messages.warnings.length
195195
) {
196-
console.log(
197-
chalk.yellow(
198-
'\nTreating warnings as errors because process.env.CI = true.\n' +
199-
'Most CI servers set it automatically.\n'
200-
)
201-
);
202-
return reject(new Error(messages.warnings.join('\n\n')));
196+
// Ignore sourcemap warnings in CI builds. See #8227 for more info.
197+
const filteredWarnings = messages.warnings.filter(w => !/Failed to parse source map/.test(w));
198+
if (filteredWarnings.length) {
199+
console.log(
200+
chalk.yellow(
201+
'\nTreating warnings as errors because process.env.CI = true.\n' +
202+
'Most CI servers set it automatically.\n'
203+
)
204+
);
205+
return reject(new Error(filteredWarnings.join('\n\n')));
206+
}
203207
}
204208

205209
const resolveArgs = {

0 commit comments

Comments
 (0)