The problem is, webpack builds without error, and server runs without error.
When I go to the localhost, it gives error below
Error: Cannot find module 'pug'
at webpackEmptyContext (webpack:///./node_modules/express/lib_sync?:2:10)
at new View (webpack:///./node_modules/express/lib/view.js?:81:78)
at Function.render (webpack:///./node_modules/express/lib/application.js?:570:12)
at ServerResponse.render (webpack:///./node_modules/express/lib/response.js?:1008:7)
at eval (webpack:///./index.js?:84:9)
at Layer.handle [as handle_request] (webpack:///./node_modules/express/lib/router/layer.js?:95:5)
at next (webpack:///./node_modules/express/lib/router/route.js?:137:13)
at Route.dispatch (webpack:///./node_modules/express/lib/router/route.js?:112:3)
at Layer.handle [as handle_request] (webpack:///./node_modules/express/lib/router/layer.js?:95:5)
at eval (webpack:///./node_modules/express/lib/router/index.js?:281:22)
Hi,
I have my webpack config as follows
`const path = require('path');
module.exports = (env) => { return { mode: env.mode, entry: path.resolve('index.js'), output: { filename: 'bundle.js', path: dirname }, target: 'node', node: { dirname: true, __filename: true }, module: { rules: [ { test: /.js$/, loader: 'babel-loader', exclude: /node_modules/, options: { presets: ['@babel/preset-env'], plugins: ["@babel/plugin-transform-runtime"] } }, { test: /.pug#/, loader: 'pug-loader', exclude: /node_modules/ } ] } } }`
I have my express server like below:
app.get('/', (req, res) => { res.render('index', { title: 'DashMon Application', message: 'Sample App', content }) }); app.get('/info', (req, res) => { res.send(content); }); app.listen(port, () => { console.log(
Listening on port ${port}); });
The problem is, webpack builds without error, and server runs without error. When I go to the localhost, it gives error below
Error: Cannot find module 'pug' at webpackEmptyContext (webpack:///./node_modules/express/lib_sync?:2:10) at new View (webpack:///./node_modules/express/lib/view.js?:81:78) at Function.render (webpack:///./node_modules/express/lib/application.js?:570:12) at ServerResponse.render (webpack:///./node_modules/express/lib/response.js?:1008:7) at eval (webpack:///./index.js?:84:9) at Layer.handle [as handle_request] (webpack:///./node_modules/express/lib/router/layer.js?:95:5) at next (webpack:///./node_modules/express/lib/router/route.js?:137:13) at Route.dispatch (webpack:///./node_modules/express/lib/router/route.js?:112:3) at Layer.handle [as handle_request] (webpack:///./node_modules/express/lib/router/layer.js?:95:5) at eval (webpack:///./node_modules/express/lib/router/index.js?:281:22)
How do I solve this? Thanks