Skip to content

Warning: Critical dependencies. #196

Closed

Description

@fresheneesz

What does this warning mean? Can this warning give a little more information as to its significance and what you might want to do about it (or perhaps where to find more information about it)?

Activity

  1. added a commit that references this issue on Mar 11, 2014
    61f1c4d
  2. sokra commented on Mar 11, 2014

    @sokra
    Member

    added better warning message

  3. fresheneesz commented on Mar 11, 2014

    @fresheneesz
    ContributorAuthor

    Ah, so its a warning that one of the dependencies is an expression. Thanks Sokra!

    I would suggest that calling it a "critical dependency" doesn't quite describe what it is. Critical dependency makes me think of a dependency that must exist for things to work. Instead, this is simply warning about a dependency written as an expression. I would leave out the words "Critical dependency" and just let "the request of a dependency is an expression" describe it. Its much more understandable now tho.

  4. kentcdodds commented on Jan 19, 2015

    @kentcdodds

    Would there be a way to suppress this warning for 3rd party libraries? I don't want to get this every time I build just because I have a dependency that does this.

  5. MarkNijhof commented on Jan 28, 2015

    @MarkNijhof

    +1 on suppressing

  6. jhnns commented on Jan 28, 2015

    @jhnns
    Contributor

    Would there be a way to suppress this warning for 3rd party libraries? I don't want to get this every time I build just because I have a dependency that does this.

    This error should not be ignored. It usually means that every file below a certain path will be included into the bundle (which should certainly not be ignored).

    It always needs to be resolved with aliasing or require contexts

  7. MarkNijhof commented on Jan 28, 2015

    @MarkNijhof

    Can I then suggest the error points to these two links?

    On Wednesday, January 28, 2015, Johannes Ewald [email protected]
    wrote:

    Would there be a way to suppress this warning for 3rd party libraries? I
    don't want to get this every time I build just because I have a dependency
    that does this.

    This error should not be ignored. It usually means that every file
    below a certain path will be included into the bundle (which should
    certainly not be ignored).

    It always needs to be resolved with aliasing
    http://webpack.github.io/docs/configuration.html#resolve-alias or require
    contexts
    http://webpack.github.io/docs/configuration.html#automatically-created-contexts-defaults-module-xxxcontextxxx

    —
    Reply to this email directly or view it on GitHub
    #196 (comment).

    Mark Nijhof
    t: @MarkNijhof https://twitter.com/MarkNijhof
    s: marknijhof

  8. jhnns commented on Jan 28, 2015

    @jhnns
    Contributor

    The error message is confusing, yes @sokra.

    Unfortunately these problems can not be solved all the same way. It heavily depends on what the library author is trying to achieve, but almost always it can be avoided at all. See #733 and ansman/validate.js#12 (comment)

  9. MarkNijhof commented on Jan 28, 2015

    @MarkNijhof

    But I have no direct influence in how a third party lib does things. Can
    this be solved without touching their code? Else a way to supres individual
    errors would be great

    On Wednesday, January 28, 2015, Johannes Ewald [email protected]
    wrote:

    The error message is confusing, yes @sokra https://github.com/sokra.

    Unfortunately these problems can not be solved all the same way. It
    heavily depends on what the library author is trying to achieve, but almost
    always it can be avoided at all. See #733
    #733 and ansman/validate.js#12
    (comment)
    ansman/validate.js#12 (comment)

    —
    Reply to this email directly or view it on GitHub
    #196 (comment).

    Mark Nijhof
    t: @MarkNijhof https://twitter.com/MarkNijhof
    s: marknijhof

  10. kentcdodds commented on Jan 28, 2015

    @kentcdodds

    @MarkNijhof, I believe that's what @jhnns is saying. Using aliases, require contexts, or some other mechanism, there is a way to fix the issue. webpack is powerful.

  11. MarkNijhof commented on Jan 28, 2015

    @MarkNijhof

    Ah misunderstood, and yes very happy with webpack

    On Wednesday, January 28, 2015, Kent C. Dodds [email protected]
    wrote:

    @MarkNijhof https://github.com/MarkNijhof, I believe that's what @jhnns
    https://github.com/jhnns is saying. Using aliases, require contexts, or
    some other mechanism, there is a way to fix the issue. webpack is powerful.

    —
    Reply to this email directly or view it on GitHub
    #196 (comment).

    Mark Nijhof
    t: @MarkNijhof https://twitter.com/MarkNijhof
    s: marknijhof

  12. sokra commented on Jan 28, 2015

    @sokra
    Member

    Try the ContextReplacmentPlugin...

  13. MarkNijhof commented on Jan 28, 2015

    @MarkNijhof

    Thanks will try tomorrow :-)

    On Wednesday, January 28, 2015, Tobias Koppers [email protected]
    wrote:

    Try the ContextReplacmentPlugin...

    —
    Reply to this email directly or view it on GitHub
    #196 (comment).

    Mark Nijhof
    t: @MarkNijhof https://twitter.com/MarkNijhof
    s: marknijhof

  14. ayozebarrera commented on Jan 19, 2016

    @ayozebarrera

    I had the same warning using:

    let Class = require(url);

    and the warning disappeared when I did the following:

    let Class = require(`${url}`);

    Should I worry about this thing?

    Thanks!

  15. 101 remaining items

  16. lchioukh commented on Apr 16, 2020

    @lchioukh

    This warning can be linked to packages injections in (dependancies or devDependencies).

    If the problem suddenly appears, check the last modification in your package.json.

    Consider removing package-lock.json if you plan to relaunch an npm install.

  17. Ancientshield commented on Apr 24, 2020

    @Ancientshield
    08:29:10 webpack.1 |                                      Asset       Size       Chunks                         Chunk Names
    08:29:10 webpack.1 |     js/application-e6df12ccd2f6f43a2d3c.js   5.65 MiB  application  [emitted] [immutable]  application
    08:29:10 webpack.1 | js/application-e6df12ccd2f6f43a2d3c.js.map   5.62 MiB  application  [emitted] [dev]        application
    08:29:10 webpack.1 |       js/tagsinput-e4036152fa3328826ac2.js    427 KiB    tagsinput  [emitted] [immutable]  tagsinput
    08:29:10 webpack.1 |   js/tagsinput-e4036152fa3328826ac2.js.map    481 KiB    tagsinput  [emitted] [dev]        tagsinput
    08:29:10 webpack.1 |                              manifest.json  689 bytes               [emitted]
    08:29:10 webpack.1 |
    08:29:10 webpack.1 | WARNING in ./node_modules/express/lib/view.js 74:13-25
    08:29:10 webpack.1 | Critical dependency: the request of a dependency is an expression
    08:29:10 webpack.1 |     at CommonJsRequireContextDependency.getWarnings (/Users/rd/training/node_modules/webpack/lib/dependencies/ContextDependency.js:40:18)
    08:29:10 webpack.1 |     at Compilation.reportDependencyErrorsAndWarnings (/Users/rd/training/node_modules/webpack/lib/Compilation.js:1454:24)
    08:29:10 webpack.1 |     at /Users/rd/training/node_modules/webpack/lib/Compilation.js:1258:10
    08:29:10 webpack.1 |     at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/rd/start_training/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    08:29:10 webpack.1 |     at AsyncSeriesHook.lazyCompileHook (/Users/rd/training/node_modules/tapable/lib/Hook.js:154:20)
    08:29:10 webpack.1 |     at Compilation.finish (/Users/rd/training/node_modules/webpack/lib/Compilation.js:1253:28)
    08:29:10 webpack.1 |     at /Users/rd/training/node_modules/webpack/lib/Compiler.js:672:17
    08:29:10 webpack.1 |     at _done (eval at create (/Users/rd/training/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    08:29:10 webpack.1 |     at eval (eval at create (/Users/rd/training/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:20:22)
    08:29:10 webpack.1 |     at /Users/rd/training/node_modules/webpack/lib/Compilation.js:1185:12
    08:29:10 webpack.1 | ℹ 「wdm」: Compiled with warnings.
    
  18. smac89 commented on Apr 27, 2020

    @smac89

    Such an annoying warning. I solved this by using the following in webpack.config.js:

    stats: {
        warningsFilter: [/critical dependency:/i],
    }
  19. ChrisSargent commented on May 18, 2020

    @ChrisSargent

    I'm working on a lambda application with AWS amplify, hence my need for bundling (so I can't exclude Node Externals for example). I am seeing this error from a package (https://github.com/Nike-Inc/lambda-logger-node) which includes the following code:

    function hasModuleLoaded(moduleName) {
      try {
        return !!require.cache[require.resolve(moduleName)]
      } catch (e) {
        if (/Cannot find module/.test(e.toString())) return false
        throw e
      }
    }

    Also, looking at another npm module, I can see the code does a similar thing which produces this error: https://github.com/kownacki/module-available/blob/master/index.js

    "use strict";
    
    module.exports = function(moduleName) {
        if (typeof moduleName !== "string") {
            throw new TypeError("Passed parameter must be a string.");
        }
    
        try {
            require.resolve(moduleName);
        }
        catch (error) {
            if (error.code === "MODULE_NOT_FOUND") {
                return false;
            }
            throw error;
        }
        return true;
    };

    It kind of seems a legitimate use case for this kind of requiring so I'm just wondering what the recommended way of handling this could be?

    EDIT: Actually, I guess the issue in a 'bundled' app is that require.resolve will always return false. But still, I wonder how to therefore suppress the error using the ContextReplacementPlugin?

  20. tstibbs commented on Aug 28, 2020

    @tstibbs

    I've read the many comments on this issue and still can't work out how to get rid of the error. It's fine when it's your own code and you can use require contexts, but if it's in a third-party module that you don't control, then it's harder. In my case, bundling Mocha causes this error, but it still works fine because I don't use any of the functionality that's affected. So, I just want to suppress the warning.

    In case it helps anyone else, here's the best I could come up with. It's a dirty hack that looks for the path that mocha is trying to load from (.) and then checks that it is indeed mocha that's trying to load from it, and if so tells it to look for things using a regex that should never match anything.

    new webpack.ContextReplacementPlugin(
        /^\.$/,
        (context) => {
            if (/\/node_modules\/mocha\/lib/.test(context.context)) {//ensure we're only doing this for modules we know about
                context.regExp = /this_should_never_exist/
                for (const d of context.dependencies) {
                    if (d.critical) d.critical = false;
                }
            }
        }
    )

    (add the above to plugins in your webpack config)

  21. macrozone commented on Feb 10, 2021

    @macrozone

    I also have this with this library https://github.com/jeanlescure/short-unique-id

    i use it in another library and now this "warning" leaks into any consumer of my library, altough nothing seems to be wrong at all.

    I have to do something about it, does someone have an idea how to supress it for any consumer of my library?

  22. johndiiorio commented on Jul 30, 2021

    @johndiiorio

    I wanted to share my own findings in investigating these warnings. In my experience, even though they can be suppressed (e.g. with exprContextCritical: false or by tricking webpack with template literal strings), they are usually indicative of some real issue and should be addressed, especially if they appear suddenly. If you are doing things on the backend, try using webpack-node-externals to not bundle your node_modules. In my case, I switched to a monorepo setup (e.g. Lerna / Yarn workspaces / NPM workspaces) and was using webpack-node-externals, but ran into this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions