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

[DX Enhancement] Suppress missing dep warning from Webpack #33

Closed
5 of 6 tasks
mornir opened this issue Oct 27, 2020 · 3 comments
Closed
5 of 6 tasks

[DX Enhancement] Suppress missing dep warning from Webpack #33

mornir opened this issue Oct 27, 2020 · 3 comments

Comments

@mornir
Copy link
Contributor

mornir commented Oct 27, 2020

Version

module: 0.3.9
nuxt: 2.14.6

Nuxt mode

mode:

  • universal
  • spa

Nuxt configuration

https://github.com/mornir/terminofeu-web/blob/dev/nuxt.config.js

Reproduction

https://github.com/mornir/terminofeu-web

Link:

  • GitHub repository

What is expected?

The following warning is not shown when client is set to minimal: Warning: Module not found: Error: Can't resolve '@sanity/client'

What is actually happening?

Warning is shown regardless of minimal setting

Additional information

If the minimal key is missing, the warning is correct: " To disable this warning, set sanity: { minimal: true } in your nuxt.config.js."

Checklist

  • I have tested with the latest Nuxt version and the issue still occurs
  • I have tested with the latest module version and the issue still occurs
  • I have searched the issue tracker and this issue hasn't been reported yet
@mornir mornir added the bug Something isn't working label Oct 27, 2020
@mornir mornir changed the title When setting minimal to true, warning are still showing in the console When setting minimal to true, warnings about missing "@sanity/client" are still showing in the console Oct 27, 2020
@danielroe
Copy link
Collaborator

@mornir Thanks for this! This warning is generated by webpack because require('@sanity/client') is present in the module code, even though it isn't being run. It's not a bug, just an annoyance.

However, I'll see what I can do.

@danielroe danielroe removed the bug Something isn't working label Oct 28, 2020
@mornir
Copy link
Contributor Author

mornir commented Oct 28, 2020

Yes, it's just a bit annoying with HMR. The warning is printed at every saves.

@mornir
Copy link
Contributor Author

mornir commented Oct 28, 2020

I had a (amateur) look into it. Actually the following line just checks if the dependency "@sanity/client" is installed, returning a boolean?
!!(process.client || process.server ? require.resolveWeak("@sanity/client") : require("@sanity/client"));
What puzzles me is that this block of code is not even executed when minimal is set to true and the error is not caught by the try/catch blocks. Like you said, this is just Webpack trying to be helpful by showing that warning. (Curious to see if Webpack 5 throws the same warning.)

I did some research online and I didn't find anything conclusive to suppress that warning.

If I do install the @sanity/client dependency and set minimal to true, I'm guessing that @sanity/client won't be included in the production bundle? I can live with that solution.

Another solution would be to just remove that check. Then instead of a nice consola warning, the console would print:
This dependency was not found: @sanity/client. If this solution is chosen, I would change the default value of minimal to true.

@mornir mornir changed the title When setting minimal to true, warnings about missing "@sanity/client" are still showing in the console [DX Enhancement] Suppress missing dep warning from Webpack Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants