Search code examples
javascriptnpmwebpackpackageparceljs

How to resolve "Critical dependency: the request of a dependency is an expression" error for my npm package?


I have a package called all-keyboardevent-keys that exports an object of keyboardevent strings. This package is a dependency in another package that I created, onkey-event-manager, which I have included in a Gatsby site.

Whenever I start the Gatsby development server on my site, I get the following warning:

WARNING  Compiled with 1 warnings

warning  in ./node_modules/all-keyboardevent-keys/lib/index.js

Critical dependency: the request of a dependency is an expression

In searching around, I have learned that this warning comes from webpack, a library that I know little about.

I would love to resolve this warning in my package so other users don't have a problem. Unfortunately, most of the answers on this site and others are for end users and not package maintainers.

What can I do, as a package author, to resolve this warning?


Solution

  • The dependency package in question, all-keyboard-events, had not been built correctly. I replaced Parcel with Babel, updated the build configurations, built again, and the error was resolved.

    I thought this was an instance of Webpack being too particular; instead it was catching an error that my tests cases had missed.

    Hopefully that is helpful for anyone else experiencing the same issue.