-
Notifications
You must be signed in to change notification settings - Fork 404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't use it with yarn2 #555
Comments
I think that "Yarn 2" (it actually should never be called Yarn 2, it's a completely different library) currently doesn't support many other things as well. I would recommend sticking with "Yarn 1" for now. |
Yarn Berry (2) introduced some pretty hefty changes, the most notable being forced adoption of their PnP module resolution scheme, which requires patching of Node.JS's require API. This is usually done transparently by yarn ( There are some pretty significant benefits to PnP compared to the current state of npm, however, such as reducing the NestJS starter template from 193 MB of node_modules dependencies to only 55 MB (size on disk), and reducing the number of files, (which is arguably much more important) from 31,873 to only 1,904 (with a similar reduction in folder count as well). This means faster start-up times, faster installs, much faster deployment with bundled dependencies, and even the possibility of actually committing dependencies due to a more deterministic and flat install structure. Plus, with Yarn's native workspaces, it's easier than ever to set up a monorepo with nested dependencies that are correctly installed, scoped and resolved from the root, without the lerna symlink bootstrap pain, and eventual crying when you realise that by using typescript, you need an additional prebuild step and deployment of the entire node_modules folder if you decide to symlink any packages. The node_mobules folder is a long-running joke and despite PnP being far from standard, it might be worth taking a look into. npm seem to have abandoned their tink project last year (main dev left the company), and many major tools, such as Gatsby, CRA, seem to be looking into supporting PnP, with others such as Jest, Typescript, Webpack, Babel working already (mostly) out of the box. |
@kamilmysliwiec could you please reconsider reopening this issue? Yarn2 can really improve the DX. |
A problem why @nestjs/cli won't start is the complex manual resolution algorithm found in https://github.com/nestjs/nest-cli/blob/master/lib/compiler/typescript-loader.ts that only searches for typescript on disk & in node_modules folders. Those don't exist any more with yarn-pnp. As a dirty workaround, you can just patch that, though. Include this code in your project as diff --git a/lib/compiler/typescript-loader.js b/lib/compiler/typescript-loader.js
index 0011917c..3a45f378 100644
--- a/lib/compiler/typescript-loader.js
+++ b/lib/compiler/typescript-loader.js
@@ -4,6 +4,7 @@ const fs_1 = require("fs");
const path_1 = require("path");
class TypeScriptBinaryLoader {
load() {
+ return require("typescript");
if (this.tsBinary) {
return this.tsBinary;
} and then edit your
|
@kamilmysliwiec Since the fix for this seems pretty simple, isn't it worth to take another look at this? After trying around a bit with @phryneas fix (thanks for sharing that!) I couldn't find anything that doesn't work as expected (albeit with a very simple setup). A naive fix could be: class TypeScriptBinaryLoader {
load () {
if ('BERRY_BIN_FOLDER' in process.env.) {
return require('typescript')
}
// rest of loading routine
}
}
|
You can check for |
Wow, that was fast! Thank you. Maybe another argument for implementing this - I created a new project using yarn 2 with PnP enabled:
yarn 2 with
yarn 1:
|
@TimonLukas If this can be fixed with ~1 additional condition without affecting anything else, PRs are more than welcome. :) |
It'd be great if NestJS could be deployed with Yarn 2. Thanks for the ticket. Hopefully it will benefit the whole community! |
It should be fixed in 7.4.0 |
@TimonLukas hi, I am trying to create a monorepo with different nest API and services but it is not clear to me how to do it with yarn workspaces. I think mainly because it is not clear to me how to create yarn workspaces, yarn doc is not helping me a lot.. |
@StefanoAgazzi I haven't used Nest with a workspaces setup yet, but I have used workspaces in other projects and it's actually quite simple to set up. Let's go with a very simple example, you have a project that has a frontend and a backend, and you want them managed using workspaces (not the example where you get the most out of the workspaces, but it's good enough to show the process. The folder structure could look like this:
Then, in your That's everything you have to do! Now, if you install the dependencies by executing |
@TimonLukas: Sorry if I'm confused by this thread but is yarn v2 supported by NestJS? The comment above by @kamilmysliwiec makes me think that you wrote a PR fixing it and it is supported in version > 7.4.0. I've tried converting an existing next project into a yarn v2 monorepo but am unable to get it working (see below for details). Am I misreading this issue or just doing something wrong in the configuration? Yarn v2 IssuesI changed the package.json scripts to use yarn instead of referencing "prebuild": "yarn rimraf dist",
"build": "yarn nest build",
"start": "yarn nest start",
etc... Using this I can use |
@Ghirigoro I have various projects running NestJS on Yarn 2 with PnP successfully. At a minimum, you may need to add the following to your packageExtensions:
"@nestjs/core@*":
peerDependenciesMeta:
"@nestjs/platform-express":
optional: true
"@nestjs/graphql@*":
dependencies:
apollo-env: 0.6.5
graphql-tools: 6.0.13
peerDependencies:
apollo-server-express: "*" Then run I have opened various PRs across Also see #899 which you can temporarily patch by adding "resolutions": {
"@nestjs/cli": "patch:@nestjs/cli@7.5.1#./.yarn/patches/nest-cli.patch"
} and this patch: https://gist.github.com/andreialecu/f29591e693e27575745fda7e21eaf865 |
@andreialecu: Thanks! Adding the |
You probably need to add it to |
@andreialecu I've tried that but with no success. Or at least I thought I did. This is what I have for my yarnPath: ".yarn/releases/yarn-berry.cjs"
packageExtensions:
"@nestjs/core@*":
peerDependencies:
"class-validator": "*"
peerDependenciesMeta:
"class-validator":
optional: true
"@nestjs/platform-express":
optional: true In any case thanks for all your help |
@Ghirigoro I think those should work. Remember to run |
@andreialecu I ran |
@Ghirigoro do you have |
@andreialecu I do have both "dependencies": {
"@nestjs/bull": "^0.2.2",
"@nestjs/common": "^7.4.4",
"@nestjs/core": "^7.4.4",
"@nestjs/platform-express": "^7.4.4",
"aws-sdk": "^2.771.0",
"bull": "^3.18.0",
"class-transformer": "^0.3.1",
"class-validator": "^0.12.2",
"dotenv": "^8.2.0",
"helmet": "^4.1.1",
"mobx": "5.15.7",
"mobx-state-tree": "^3.17.2",
"module-alias": "^2.2.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.5.4",
"tldts": "^5.6.60"
}, I'll try stripping the project down to just the nest bit and see if the problem is still there. If it is I'll post it. Thanks! |
@andreialecu I made a stripped down project that recreates the issue. If and when you have time you can find it here: |
@Ghirigoro it seems that those two dependencies are not used by It should work with these extensions: packageExtensions:
"@nestjs/core@*":
peerDependenciesMeta:
"@nestjs/platform-express":
optional: true
"@nestjs/common@*":
peerDependenciesMeta:
"class-validator":
optional: true
"class-transformer":
optional: true For reference on how I found them, look here: https://github.com/nestjs/nest/blob/85c6be1a4094f9abc6699984b9b564eea54edc38/packages/common/pipes/validation.pipe.ts#L63-L68 They should be marked as peer deps, or optional deps in https://github.com/nestjs/nest/blob/85c6be1a4094f9abc6699984b9b564eea54edc38/packages/common/package.json but they are not. |
@andreialecu Yeah, I set Should the missing dependencies be flagged as bugs or is this part of a future upgrade to yarn v2 support? |
They're bugs, essentially. It only worked with I'm waiting for more feedback from @kamilmysliwiec here: But I think a core NestJS maintainer should go over all dependencies and ensure everything is properly depended on. |
I'm submitting a...
Current behavior
outputs:
⚡ We will scaffold your app in a few seconds..
and do not create my projectExpected behavior
A new folder with the project
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Yarn team recently released Yarn berry, the 2.0 version of yarn with a lot of new cool stuff, but unfortunately they don't support global packages the same way yarn 1 does. I think that adding support to it would be a nice feature
Environment
(No package.json because i could'nt create the project)
The text was updated successfully, but these errors were encountered: