-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
needs triageThis issue has not been looked intoThis issue has not been looked into
Description
Bug Report
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:
express tried to access pug, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
Required package: pug (via "pug")
Required by: express@npm:4.17.1 (via /Users/bchinn/Desktop/yarn2/express-pug-error/.yarn/cache/express-npm-4.17.1-6815ee6bf9-c4b470d623.zip/node_modules/express/lib/)
Require stack:
- /Users/bchinn/Desktop/yarn2/express-pug-error/.yarn/cache/express-npm-4.17.1-6815ee6bf9-c4b470d623.zip/node_modules/express/lib/view.js
- /Users/bchinn/Desktop/yarn2/express-pug-error/.yarn/cache/express-npm-4.17.1-6815ee6bf9-c4b470d623.zip/node_modules/express/lib/application.js
- /Users/bchinn/Desktop/yarn2/express-pug-error/.yarn/cache/express-npm-4.17.1-6815ee6bf9-c4b470d623.zip/node_modules/express/lib/express.js
- /Users/bchinn/Desktop/yarn2/express-pug-error/.yarn/cache/express-npm-4.17.1-6815ee6bf9-c4b470d623.zip/node_modules/express/index.js
- /Users/bchinn/Desktop/yarn2/express-pug-error/.yarn/$$virtual/@nestjs-platform-express-virtual-71cd35a84f/0/cache/@nestjs-platform-express-npm-7.5.5-1f245a935a-8af8bba8dc.zip/node_modules/@nestjs/platform-express/adapters/express-adapter.js
- /Users/bchinn/Desktop/yarn2/express-pug-error/.yarn/$$virtual/@nestjs-platform-express-virtual-71cd35a84f/0/cache/@nestjs-platform-express-npm-7.5.5-1f245a935a-8af8bba8dc.zip/node_modules/@nestjs/platform-express/adapters/index.js
- /Users/bchinn/Desktop/yarn2/express-pug-error/.yarn/$$virtual/@nestjs-platform-express-virtual-71cd35a84f/0/cache/@nestjs-platform-express-npm-7.5.5-1f245a935a-8af8bba8dc.zip/node_modules/@nestjs/platform-express/index.js
- /Users/bchinn/Desktop/yarn2/express-pug-error/.yarn/unplugged/@nestjs-core-virtual-74f5478e67/node_modules/@nestjs/core/nest-factory.js
- /Users/bchinn/Desktop/yarn2/express-pug-error/.yarn/unplugged/@nestjs-core-virtual-74f5478e67/node_modules/@nestjs/core/index.js
- /Users/bchinn/Desktop/yarn2/express-pug-error/foo/dist/main.js +9467ms
I couldn't repro this in a repo using just express, which is why I'm writing this in the NestJS project.
Repro instructions
mkdir express-pug-error && cd express-pug-error
yarn set version berry
yarn init
# having trouble bootstrapping with yarn v2. just use npm for now
npm install @nestjs/cli
node_modules/.bin/nest new foo
# "Which package manager would you <3 to use?" => yarnUpdate package.json
{
"name": "express-pug-error",
+ "private": true,
+ "workspaces": ["foo"]
}yarn workspace foo add @nestjs/platform-expressAdd to .yarnrc.yml (since #5477 isn't uploaded to npm yet)
packageExtensions:
'@nestjs/testing@*':
peerDependencies:
'@nestjs/platform-express': '*'
'@nestjs/core@*':
peerDependencies:
'@nestjs/microservices': '*'
'@nestjs/platform-express': '*'
'@nestjs/websockets': '*'Make the following additions:
diff --git a/foo/src/app.controller.ts b/foo/src/app.controller.ts
index cce879e..23ffd92 100644
--- a/foo/src/app.controller.ts
+++ b/foo/src/app.controller.ts
@@ -1,4 +1,4 @@
-import { Controller, Get } from '@nestjs/common';
+import { Controller, Get, Render } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
@@ -6,7 +6,8 @@ export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
+ @Render('index')
- getHello(): string {
- return this.appService.getHello();
+ getHello() {
+ return {}
}
}
diff --git a/foo/src/main.ts b/foo/src/main.ts
index 13cad38..9c28104 100644
--- a/foo/src/main.ts
+++ b/foo/src/main.ts
@@ -1,8 +1,10 @@
import { NestFactory } from '@nestjs/core';
+import { NestExpressApplication } from '@nestjs/platform-express'
import { AppModule } from './app.module';
async function bootstrap() {
- const app = await NestFactory.create(AppModule);
+ const app = await NestFactory.create<NestExpressApplication>(AppModule);
+ app.setViewEngine('pug')
await app.listen(3000);
}
bootstrap();yarn
yarn workspace foo startcurl localhost:3000Input Code
const your = (code) => here;Expected behavior
Possible Solution
Environment
Nest version: X.Y.Z
For Tooling issues:
- Node version: XX
- Platform:
Others:
Metadata
Metadata
Assignees
Labels
needs triageThis issue has not been looked intoThis issue has not been looked into