Webpack and Express - Critical Dependencies Warning Webpack and Express - Critical Dependencies Warning express express

Webpack and Express - Critical Dependencies Warning


Use webpack-node-externals.

const nodeExternals = require('webpack-node-externals');{  target: 'node',  externals: [nodeExternals()],}

https://www.npmjs.com/package/webpack-node-externals


For those that only need to remove the express due to the view lib as mentioned here you can also explicitly target express in externals from your webpack config.

externals: [{ 'express': { commonjs: 'express' } }]


Instead of excluding all of the npm dependencies to be bundled with nodeExternals you can also exclude only express by natively requiring it by replacing

import express from 'express';// Orconst express = require('express');

To

const express = __non_webpack_require__('express');

That will suppress the warning caused by express