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

Warning when using with webpack #45

Closed
fantapop opened this issue Jan 25, 2018 · 14 comments
Closed

Warning when using with webpack #45

fantapop opened this issue Jan 25, 2018 · 14 comments

Comments

@fantapop
Copy link

I'm importing https://github.com/sindresorhus/got/ into my project and using webpack to build. Webpack doesn't like requiring of expressions:

WARNING in ./node_modules/keyv/src/index.js
18:14-40 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/keyv/src/index.js
 @ ./node_modules/cacheable-request/src/index.js
 @ ./node_modules/got/index.js
 @ ./lib/util.js
 @ ./functions/live-stream.js

I'm not sure what the best way to fix this up with would be

@lukechilds
Copy link
Contributor

Does it work?

@fantapop
Copy link
Author

fantapop commented Jan 25, 2018 via email

@lukechilds
Copy link
Contributor

lukechilds commented Jan 25, 2018

It should work absolutely fine as long as you're not including native Node.js storage adapters.

The Webpack warning is exactly that a warning, it's letting you know that one of your dependencies is requiring a dependency via an expression.

This is generally bad practice and will probably break static analysis but it's the only way to transparently require storage adapters.

It should be totally safe to ignore for now.

@roblav96
Copy link

roblav96 commented Mar 7, 2018

@fantapop @lukechilds What's the recommended quick fix to remove the warnings from my console? I run a tight ship 📦:P

@lukechilds
Copy link
Contributor

Close your eyes while the warning's on the screen.

@sindresorhus
Copy link

This has just another bad Webpack UX. I would recommend complaining on their issue tracker: webpack/webpack#196

@fantapop
Copy link
Author

fantapop commented Mar 7, 2018 via email

@Tobbe
Copy link

Tobbe commented Jan 7, 2021

Don't know if this is good or bad, but I added this to my webpack config to get rid of the warning

plugins: [
  new webpack.ContextReplacementPlugin(/keyv/),
],

@transitive-bullshit
Copy link

It turns out this isn't a wholly innocuous warning.

If you're using Next.js on Vercel, as part of their build optimizations for serverless functions (like dynamic page rendering), they trace module imports to remove as much unused code as possible.

It took me awhile to realize that while I'm using keyv with next.js v12 (and webpack v5) locally, everything would build and work fine, but when deployed to Vercel, any page renders or api calls would throw errors because next.js failed to find the expression-based @keyv/redis import.

If anyone else ends up here tracking this issue down, here was my fix: transitive-bullshit/nextjs-notion-starter-kit@2226296

While I can understand keyv's design choice to have a simpler, implicit API, and while you could certainly argue that Next.js's behavior is aggressive, it's honestly a pretty common use case these days — and one that I think will only become more common in the future.

@transitive-bullshit
Copy link

https://github.com/microlinkhq/keyv by @Kikobeats appears to fix this issue, but upstream dependents like https://github.com/lukechilds/cacheable-request (which is used by got) would need to change. Or this package would need to update its API in the same way that @keyvhq/core has.

Either way, I think this is worth fixing as it is definitely affecting anyone using got with Next.js.

@Kikobeats
Copy link
Contributor

@transitive-bullshit

Although @keyvhq/core fix the thing, there are still place where the dependency will be not used (like cacheable-request sub-dependencies tree).

For these situations, you can declare a NPM override at your package.json 🙂

"overrides": {
    "cacheable-request": {
      "keyv": "npm:@keyvhq/core@~1.6.6"
    }
  }

@nickluger
Copy link

I use this package transitively via got and see this issue only, since got upgraded indirectly to 4.5.0 of keyv. 🤷‍♂️

@AuthorOfTheSurf
Copy link

In my case I needed to update my badly-outdated @auth0/nextjs-auth0 dependency to the latest version. Some of my imports changed to look like @auth0/nextjs-auth0/client since they are client-side

My old auth0 dep was relying on cacheable-request and therefore keyv which I hadn't heard of till today. All of this can be seen in the error stack depending on your case

I encountered this bug when porting a NextJS 12 app to NextJS 13, so I suspect others may find their way here. In my case the error had a natural solution, and I was able to update an important security dependency

@Azleal
Copy link

Azleal commented Apr 28, 2024

the warning is still there, any solutions?

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

10 participants