Skip to content
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

fix: ignore webpack warnings by source-map-loader #11752

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Bnaya
Copy link

@Bnaya Bnaya commented Dec 14, 2021

Some third party packages may ship miss-configured sourcemaps, that interrupts the build
See: #11278 (comment)

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

Some third party packages may ship miss-configured sourcemaps, that interrupts the build
See: facebook#11278 (comment)
@Bnaya Bnaya marked this pull request as ready for review December 14, 2021 19:35
@raix
Copy link
Contributor

raix commented Dec 14, 2021

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

@Bnaya
Copy link
Author

Bnaya commented Dec 15, 2021

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

@raix raix added this to the 5.1 milestone Dec 15, 2021
@jd1048576
Copy link
Contributor

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

@Bnaya
Copy link
Author

Bnaya commented Dec 16, 2021

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

@raix
Copy link
Contributor

raix commented Dec 18, 2021

@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?

@Bnaya
Copy link
Author

Bnaya commented Dec 19, 2021

@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
Copy link
Author

Bnaya commented Dec 20, 2021

CI passes

@denchen
Copy link

denchen commented Jan 5, 2022

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.

@Bnaya
Copy link
Author

Bnaya commented Jan 6, 2022

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

@denchen
Copy link

denchen commented Jan 6, 2022

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.

@yann-combarnous
Copy link

@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.

@Bnaya
Copy link
Author

Bnaya commented Jan 10, 2022

@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

@imcodingideas
Copy link

imcodingideas commented Feb 4, 2022

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

@adamkui
Copy link

adamkui commented Mar 31, 2023

Is anyone currently working on resolving the conflicts for this PR? I think there are many of us waiting for this fix :)

@KholdStare
Copy link

Waiting for this too. Any updates?

@Rishav-k
Copy link

image
I am getting this error and i am stuck

@k-funk
Copy link

k-funk commented Jul 13, 2023

Another case where dependencies produce warnings.

my project depends on

  1. swagger-ui-react -> remarkable -> autolinker Failed to parse source map gregjacobs/Autolinker.js#396
  2. swagger-ui-react -> ... -> unraw npm package distribution - source maps errors with webpack@5 and CRA iansan5653/unraw#33

@albanx
Copy link

albanx commented Jan 22, 2024

any update on this PR? Can someone solve the conflicts and merge it?

@alleksei37
Copy link

😭😭😭😭

@saurabh-cimpress
Copy link

Any update on this please?

@reymundelosantosIII
Copy link

Any update pls.

Domar95 added a commit to Domar95/tic-tac-toe that referenced this pull request Aug 10, 2024
NOTE: set .env GENERATE_SOURCEMAP=false as a temporary solution to avoid 'Failed to parse source map...' warnings until fix is released: facebook/create-react-app#11752
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

After Uninstall create-react-app from global everytime start the development server always there is warning