Closed brandon-leapyear closed 3 years ago
:sparkles: This is an old work account. Please reference @brandonchinn178 for all future communication :sparkles:
Never mind, got it working with
app.engine('pug', require('pug').__express)
But especially as PnP gets more widespread, it seems like the current workflow of
app.engine('pug', require('pug').__express) // sets the engine for pug
app.engine('foo', require('foo').__express) // sets the engine for foo
app.set('view engine', 'pug') // sets the default
is a bit verbose and confusing (why does view engine
set the default?). I'll close this for now, but I think this configuration workflow could be improved
I am a little confused why it works without workspaces, but that's a separate question for Yarn (@arcanis if you want to step into this).
Cf this doc entry: https://yarnpkg.com/features/pnp#different-behaviours-based-on-workspace--not-a-workspace
It seems like the best solution is to have the user resolve the path to the view engine themselves
Indeed. To unblock you in the meantime, you can use packageExtensions
to declare pug
as a peer dependency of express
. That will allow Express to require it, provided the parent package properly lists it.
We're trying to upgrade to Yarn v2 in our project, which uses NestJS in a Yarn workspace. Yarn v2 adds Plug-n-Play which enforces dependencies explicitly list their dependencies. When running our server and calling an endpoint that renders a pug template, we get:
I was able to repro it below using just express, but it seems like this only happens in a workspace. If you run the
yarn
commands below in thefoo
directory (and justyarn node main.js
) it works.I am a little confused why it works without workspaces, but that's a separate question for Yarn (@arcanis if you want to step into this). It seems like the best solution is to have the user resolve the path to the view engine themselves; e.g. instead of
do
Minimal Repro
package.json
file that listsfoo/
as a workspacefoo/
withmain.js
andpackage.json
yarn set version berry
(skip this step to use yarn v1, which works)yarn
yarn workspace foo node main.js
curl localhost:3000
Yarn v2 gets me
while Yarn v1 gets me