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

unclear how to resolve critical dependencies warning for express/lib/view.js #1576

Closed
cch5ng opened this Issue Nov 2, 2015 · 18 comments

Comments

Projects
None yet
@cch5ng
Copy link

cch5ng commented Nov 2, 2015

hi, when I run webpack, I get a warning message like:

WARNING in node_modules/express/lib/view.js
Critical dependencies:
78:29-56 the request of a dependency is an expression
@ node_modules/express/lib/view.js 78:29-56

I'm not clear what I should do to resolve this. thanks.

@bebraw bebraw added the question label Nov 14, 2015

@sokra

This comment has been minimized.

Copy link
Member

sokra commented Nov 20, 2015

Don't bundle express. You can't spin up a server in the browser.

@3ginger

This comment has been minimized.

Copy link

3ginger commented Dec 28, 2015

@sokra
I have express only in server bundle, but i have the same warnings.
The config target is node.

@darrencrossley

This comment has been minimized.

Copy link

darrencrossley commented Mar 8, 2016

@cch5ng I also am seeing this issue, did you ever solve it? I'm targeting node so not sure why I'm getting a warning. I'm using Express 4.13.3.

@cch5ng

This comment has been minimized.

Copy link

cch5ng commented Mar 8, 2016

@darrencrossley, sorry, I don't really have a deep understanding of webpack. since I reported this issue, I have been referencing bebraw's book (http://survivejs.com/webpack_react/webpack_and_react/) for basic webpack config (for react, babel). I have not experienced the same issue since but I also have not needed to install express individually.

at the time I reported this, I was also new to using require or import and so there may have been user error involved.

@ufocoder

This comment has been minimized.

Copy link

ufocoder commented Mar 22, 2016

There's a dynamical requirement in ExpressJS: https://github.com/expressjs/express/blob/master/lib/view.js#L78

UPD: As I find out webpack output Critical dependencies for non obviously requirement, therefore two ways either make obviously requirement in ExpressJS or disable CriticalDependenciesWarning in webpack, but I think that the last one is not so pretty

@bebraw

This comment has been minimized.

Copy link
Member

bebraw commented Dec 24, 2016

Time to close. If still relevant, please re-open at Stack Overflow.

@bebraw bebraw closed this Dec 24, 2016

@mariohmol

This comment has been minimized.

Copy link

mariohmol commented Jun 14, 2017

Hi there... for those who get here.. use this module that it fixes all the warning for dependencies in your express app with webpac https://github.com/liady/webpack-node-externals

@psulek

This comment has been minimized.

Copy link

psulek commented Dec 13, 2017

This little "hack" works for me:

module: {
    noParse: function (content) {
        return /express/.test(content);
    }
}

Basically it "skips" parsing "expressjs".

@stephencranedesign

This comment has been minimized.

Copy link

stephencranedesign commented Dec 14, 2017

@psulek this accomplished the same thing, basically telling webpack not to include express in the generated bundle.

externals: ['express', ... ]

@psulek

This comment has been minimized.

Copy link

psulek commented Dec 15, 2017

@stephencranedesign yes you're right, that does not help, just tested it right now.

@stephencranedesign

This comment has been minimized.

Copy link

stephencranedesign commented Dec 21, 2017

@psulek - found this module and it did the trick for me: https://github.com/liady/webpack-node-externals

@ashblue

This comment has been minimized.

Copy link

ashblue commented Jan 2, 2018

https://github.com/liady/webpack-node-externals not only fixed my warnings / errors. It also reduced my file size tremendously from 2mb+ to 10kb.

@jorgemmsilva

This comment has been minimized.

Copy link

jorgemmsilva commented Jul 10, 2018

You should be aware that using webpack-node-externals will not bundle any of your node modules dependencies.
While this is the desired output for some projects, packaging all your dependencies using webpack tree shaking capabilities onto a single file can be useful.

@azizj1

This comment has been minimized.

Copy link

azizj1 commented Sep 5, 2018

What if you need to bundle your node modules? E.g., when creating an AWS lambda, your dependencies that you excluded aren't available on AWS environment, and will thus fail.

Is there a way to resolve this warning without telling webpack to not include express?

@Stanback

This comment has been minimized.

Copy link

Stanback commented Sep 15, 2018

For times where I want to bundle everything together for use on the server, the best I could do was suppress the warning by adding the following to my webpack config:

  stats: {
    warningsFilter: w => w !== 'CriticalDependenciesWarning',
  },
@azizj1

This comment has been minimized.

Copy link

azizj1 commented Sep 15, 2018

Even shorter:

config: {
    stats: {
            warningsFilter: /^(?!CriticalDependenciesWarning$)/
    }
}
@mutech

This comment has been minimized.

Copy link

mutech commented Nov 12, 2018

So far I see two approaches:

  • Not bundling node modules - e.g. express - by using webpack-node-externals
  • Ignoring the warning

Not bundling externals removes much of the motivation to bundle the express server in first place. If there is little to gain from bundling, that would be ok. The potential I see for bundling the server would be a small gain in startup time and a smaller memory footprint. Am I missing something or would this be a negligible advantage?

About ignoring the warning: So webpack warns that it can't determine what is actually being imported in view.js. What are the consequences? Would that dynamic import fail? If not, is there a risk that the import somehow interferes with bundled code? Would it simply result in potentially duplicated code? Or short: is it really safe to ignore the warning?

I read somewhere else that such warnings have to be resolved via resolve aliases or otherwise. Is that impossible for this specific occurrence?

@jmahc

This comment has been minimized.

Copy link

jmahc commented Nov 29, 2018

Keep returning to this page for the error.

Here is what helped me:

...

externals: [
  { express: 'commonjs express' },
  nodeExternals({
    whitelist: isDevelopment ? ['webpack/hot/poll?1000'] : [],
  })
]

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