webpack -Error: Cannot find module 'pug' after hitting get-api

Viewed 137

after configuring webpack in express and then an new folder fomed but when i run bundle.js it successfully give a meassage- server is running on port 3000 bout when i hit api http://localhost:3000/api/test it gives loads whole bundle .js in console and give error as

Error: Cannot find module 'pug' at t (D:\wfh\Frontend-3.0-20220119T061742Z-001\Frontend-3.0\compressed\bundle.js:2:840468) at new p (D:\wfh\Frontend-3.0-20220119T061742Z-001\Frontend-3.0\compressed\bundle.js:2:839766)

or can anyone tell me how not to have index.html output i want index.pug output

1 Answers

This is what I did on my sample project, try it out and see if it works for you too.

Basically, in your server.js (or whichever is the name of your entry server JS file), add the following:

app.set('views', path.join(DIST_DIR));
app.set('view engine', 'pug');

app.engine('pug', require('pug').__express); // <-- add this line

...

then try and build your project again.

I got the reference from the link below although it's for EJS. https://stackoverflow.com/a/53897810/11826301

Related