Reputation: 12146
I have a Node js server app which uses Express
and Pug
. I would like to bundle it to single script which can be deployed by pm2
. There seem to be several problems with this.
Cannot find module "."
and during compilation few messages like WARNING in ./node_modules/express/lib/view.js 80:29-41 Critical dependency: the request of a dependency is an expression
appear which come from dynamic imports like require(mod).__express
. I assume Webpack can't statically resolve those and does not know which dependency to include.
How can this be solved ?
Pug
compile and be part of the output js ?Upvotes: 4
Views: 1330
Reputation: 6900
It is because webpack rebundle node_modules
(already bundled) dependencies and in the case of pug, it doesn't work.
You need to use webpack-node-externals within the webpack externals
option in order to specifically ask not to re-bundle depedencies.
npm i -D webpack-node-externals
Example
// ...
const nodeExternals = require('webpack-node-externals')
module.exports = {
target: 'node',
entry: {
// ...
},
module: {
// ...
},
externals: [nodeExternals()],
output: {
// ...
},
}
Upvotes: 1