create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

fix: ignore webpack warnings by source-map-loader

Open Bnaya opened this issue 2 years ago • 45 comments

Some third party packages may ship miss-configured sourcemaps, that interrupts the build See: https://github.com/facebook/create-react-app/discussions/11278#discussioncomment-1780169

To trigger the error, simply install "[email protected]" add import {} from "stylis-plugin-rtl" somewhere in the code

before: Screen Shot 2021-12-14 at 21 34 23

After: Screen Shot 2021-12-14 at 21 35 07

Bnaya avatar Dec 14 '21 19:12 Bnaya

Not sure if everything should be ignored or only warnings regarding node modules?

raix avatar Dec 14 '21 22:12 raix

Not sure if everything should be ignored or only warnings regarding node modules?

source-maps-loader is used 99.9% of cases for node_modules only I've changed the impl to use function, maybe this will work

Bnaya avatar Dec 15 '21 08:12 Bnaya

You could use the suggested example of

ignoreWarnings: [/Failed to parse source map/]

from the source map loader docs https://github.com/webpack-contrib/source-map-loader#ignoring-warnings

jd1048576 avatar Dec 16 '21 18:12 jd1048576

https://github.com/webpack-contrib/source-map-loader#ignoring-warnings

This will not give us the desired feature of focusing on node_modules, But i'll let the maintainer to give his hint

Bnaya avatar Dec 16 '21 19:12 Bnaya

@Bnaya I've tried rerunning the tests, but seem to be an issue either with caching or lock file - When doing npm install in the create-react-app project does it generate a new package-lock.json?

raix avatar Dec 18 '21 20:12 raix

@Bnaya I've tried rerunning the tests, but seem to be an issue either with caching or lock file - When doing npm install in the create-react-app project does it generate a new package-lock.json?

I've ran npm install (With npm 8.3) and committed the updated lock file. Lets see if the CI pass

Bnaya avatar Dec 19 '21 12:12 Bnaya

CI passes

Bnaya avatar Dec 20 '21 08:12 Bnaya

I don't know how relevant this is, but I had ejected after upgrading to CRA 5, and I wanted to implement this source-map-loader change, and for the most part it worked. Except every now and then, when the dev server hot-reloads, the dev server crashes with "Cannot read 'resource' of undefined."

So the fix for me was to change the relevant line to:

warning.module?.resource.includes('node_modules') &&

(Note the optional chaining)

I don't know under what circumstances warning.module would be non-existent, so hopefully someone more knowledgable than me can chime in.

denchen avatar Jan 05 '22 22:01 denchen

I will add a null check there, even tho by webpack code/types module shouldn't be undefined. https://github.com/webpack/webpack/blob/c181294865dca01b28e6e316636fef5f2aad4eb6/lib/WebpackError.js

Regarding using optional chaining, eslint won't let me use it in the project, so i will go with old-style check

Bnaya avatar Jan 06 '22 10:01 Bnaya

I will add a null check there, even tho by webpack code/types module shouldn't be undefined. https://github.com/webpack/webpack/blob/c181294865dca01b28e6e316636fef5f2aad4eb6/lib/WebpackError.js

I was able to replicate the issue. What I did was introduce an ESLint error into one of my TSX files by simply adding:

const unusedVar = 1;

and never actually using unusedVar. This of course violates @typescript-eslint/no-unused-vars. After saving the file, the dev server crashes on re-compile:

TypeError: Cannot read property 'resource' of undefined
    at ignoreSourcemapsloaderWarnings (/Users/denchen/git/ui/config/webpack.config.js:792:26)
    at /Users/denchen/git/ui/node_modules/webpack/lib/IgnoreWarningsPlugin.js:30:8
    at Array.some (<anonymous>)
    at /Users/denchen/git/ui/node_modules/webpack/lib/IgnoreWarningsPlugin.js:29:36
    at Array.filter (<anonymous>)
    at /Users/denchen/git/ui/node_modules/webpack/lib/IgnoreWarningsPlugin.js:28:22
    at Hook.eval [as call] (eval at create (/Users/denchen/git/ui/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:16)
    at Hook.CALL_DELEGATE [as _call] (/Users/denchen/git/ui/node_modules/tapable/lib/Hook.js:14:14)
    at Compilation.getWarnings (/Users/denchen/git/ui/node_modules/webpack/lib/Compilation.js:4659:37)
    at context.cachedGetWarnings (/Users/denchen/git/ui/node_modules/webpack/lib/stats/DefaultStatsFactoryPlugin.js:487:20)

(node:89082) UnhandledPromiseRejectionWarning: RpcIpcMessagePortClosedError: Cannot send the message - the message port has been closed for the process 89082.
    at /Users/denchen/git/ui/node_modules/fork-ts-checker-webpack-plugin/lib/rpc/rpc-ipc/RpcIpcMessagePort.js:47:47
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:89082) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:89082) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

As stated in my original comment, I have ejected CRA with very minimal config changes, so I don't know how relevant my error is for non-ejected CRA.

denchen avatar Jan 06 '22 16:01 denchen

@Bnaya , to be on-par with CRA4 when it comes to webpack dev server logging, could you consider adding

stats: 'errors-warnings'

to webpack.config.json?

This will get rid of all the assets bundling verbosity introduced in CRA5, while keeping warnings and errors displayed.

yann-combarnous avatar Jan 10 '22 12:01 yann-combarnous

@Bnaya , to be on-par with CRA4 when it comes to webpack dev server logging, could you consider adding

stats: 'errors-warnings'

to webpack.config.json?

This will get rid of all the assets bundling verbosity introduced in CRA5, while keeping warnings and errors displayed.

I think It's out of the scope of this PR

Bnaya avatar Jan 10 '22 12:01 Bnaya

Just a fly on the wall here, and following this topic as were affected by this as well.

imcodingideas avatar Feb 04 '22 16:02 imcodingideas

Still affected by this.

wasurocks avatar Apr 17 '22 16:04 wasurocks

Bump. Any updates on this?

jeongmincho avatar Apr 28 '22 22:04 jeongmincho

Thanks @Bnaya, that fixed my problem. If you're impatient like me, you can add this fix by editing the file node_modules/react-scripts/config/webpack.config.js, and pasting this after the line performance: false,.

    ignoreWarnings: [
      // Ignore warnings raised by source-map-loader.
      // some third party packages may ship miss-configured sourcemaps, that interrupts the build
      // See: https://github.com/facebook/create-react-app/discussions/11278#discussioncomment-1780169
      /**
       *
       * @param {import('webpack').WebpackError} warning
       * @returns {boolean}
       */
      function ignoreSourcemapsloaderWarnings(warning) {
        return (
          warning.module &&
          warning.module.resource.includes('node_modules') &&
          warning.details &&
          warning.details.includes('source-map-loader')
        );
      },
    ],

nickodell avatar May 23 '22 18:05 nickodell

This would solve my issue too.. Should be merged.

gabrielmicko avatar May 25 '22 13:05 gabrielmicko

Temporary solution for projects using customize-cra & react-app-rewired: Change following file: config-overrides.js:

const { override } = require('customize-cra');

const addIgnoreSourcemapsloaderWarnings = config => {
  config.ignoreWarnings = [
    // Ignore warnings raised by source-map-loader.
    // some third party packages may ship miss-configured sourcemaps, that interrupts the build
    // See: https://github.com/facebook/create-react-app/discussions/11278#discussioncomment-1780169
    /**
     *
     * @param {import('webpack').WebpackError} warning
     * @returns {boolean}
     */
    function ignoreSourcemapsloaderWarnings(warning) {
      return (
        warning.module &&
        warning.module.resource.includes('node_modules') &&
        warning.details &&
        warning.details.includes('source-map-loader')
      );
    },
  ];
  return config;
};

module.exports = override(
  addIgnoreSourcemapsloaderWarnings
);

Also thanks for the author of this PR to come up with the solution.

gabrielmicko avatar May 25 '22 13:05 gabrielmicko

Thanks @Bnaya, that fixed my problem. If you're impatient like me, you can add this fix by editing the file node_modules/react-scripts/config/webpack.config.js, and pasting this after the line performance: false,.

    ignoreWarnings: [
      // Ignore warnings raised by source-map-loader.
      // some third party packages may ship miss-configured sourcemaps, that interrupts the build
      // See: https://github.com/facebook/create-react-app/discussions/11278#discussioncomment-1780169
      /**
       *
       * @param {import('webpack').WebpackError} warning
       * @returns {boolean}
       */
      function ignoreSourcemapsloaderWarnings(warning) {
        return (
          warning.module &&
          warning.module.resource.includes('node_modules') &&
          warning.details &&
          warning.details.includes('source-map-loader')
        );
      },
    ],

This silences repeated sourcemap warnings for @aws-sdk, thank you!

mstephenson6 avatar Jun 04 '22 21:06 mstephenson6

If you okay to lose the sourceMaps in local, Add GENERATE_SOURCEMAP=false in .env.developement file. So that until this fix is released, you can ignore warnings in your local and still have sourceMaps in other env

sairam0903 avatar Jun 15 '22 17:06 sairam0903

Is this any closer to being fixed or is there something I can do to suppress the warning on my end? Besides the excellent suggestion to edit webpack.config.js. I would do that but I delete and reinstall node modules frequently enough that it wouldn't make much sense

TD-DO avatar Jun 30 '22 17:06 TD-DO

Is this any closer to being fixed or is there something I can do to suppress the warning on my end? Besides the excellent suggestion to edit webpack.config.js. I would do that but I delete and reinstall node modules frequently enough that it wouldn't make much sense

@TD-DO if you want an extra band-aid, for the band-aid fix, you can also use https://www.npmjs.com/package/patch-package to automatically re-apply the fix anytime your modules are reinstalled.

austin-thrive avatar Jun 30 '22 18:06 austin-thrive

Bump. Still affected. Can this be reviewed and merged?

ganeshkrishnasharma avatar Jul 08 '22 06:07 ganeshkrishnasharma

Obligatory check in, as the month is now August... Can this please be merged?!

Minho-Lee avatar Aug 02 '22 14:08 Minho-Lee

Bump.

These are not useful warnings for me, and are noise from seeing meaningful warnings. I've made an issue for the maintainers, but can only expect so much of other libraries.

WARNING in ./node_modules/@twilio/audioplayer/es5/EventTarget.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/Users/.../node_modules/@twilio/audioplayer/es5/EventTarget.js.map' file: Error: ENOENT: no such file or directory, open '/Users/.../node_modules/@twilio/audioplayer/es5/EventTarget.js.map'

k-funk avatar Aug 08 '22 02:08 k-funk

The app will work even when those warnings are showing

Faotu avatar Sep 15 '22 15:09 Faotu

Bump. Still affected. Can this be reviewed and merged?

isabellachen avatar Sep 23 '22 04:09 isabellachen

Any updates?

vladimirevstratov avatar Oct 21 '22 23:10 vladimirevstratov

We are indeed waiting for this PR to be updated and merged :)

This is just a workaround, but FYI I was able to avoid these warnings by using craco. craco allows you to overlay configuration on create-react-app without ejecting. One of its features is customizing the webpack config. Based on the config change in this PR, I put this in my craco.config.js:

module.exports = {
  webpack: {
    configure: {
      ignoreWarnings: [
        function ignoreSourcemapsloaderWarnings(warning) {
          return (
            warning.module &&
            warning.module.resource.includes('node_modules') &&
            warning.details &&
            warning.details.includes('source-map-loader')
          )
        },
      ],
    },
  },
}

graeme-hill avatar Dec 10 '22 10:12 graeme-hill