-
Notifications
You must be signed in to change notification settings - Fork 812
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
question: No metadata found. There is more than once class-validator version installed probably. You need to flatten your dependencies. #261
Comments
Same issue for me, i don't exactly get why it prints |
Hi @viktor-ku and @DavidBabel! What enviroment do you use class-validator? What other libraries do you use with it? The reason to this error as the message states there are multiple ReasonWhy do I see thisFirst, historyically Technical reasonTo understand the problem, first, we need to understand how But that storage is not shared accross the different versions of class-validator, so if you declarad a semver range in your modules the way that they doesn't share the same allowed latest version then npm will install multiple versions for you and will break it. So this is what propably is in your node_modules right now:
In the example above the module called So the folder sturcutur we want is the following:
SolutionIn short, you need to make sure to install the same class-validator accross all the projects you use together. This is most easily done by adding the same semver range, eg: Required extra stepsYou need to update npm to the latest version, npm flatten the I hope I could explain the probem (this one is hard to explain!), if anything is not clear, feel free to ask more, and I will try my best to explain it. |
This is related to #132. |
An another explanation: #181 (comment) |
@NoNameProvided I am also experiencing these errors and unable to validate. I have ensured that there is only one version of class-validator installed throughout my package tree. I have confirmed by searching the I still unfortunately get the error in my console and am unable to validate. Thanks in advance. |
Faced the same problem, this helped for me: Instead of declaring a variable with the type of the class const user: User = {
first: "John",
last: "Doe",
}; Initialize the class first before assigning data const user = User();
user.first = "John";
user.last = "Doe"; It might not be the most beautiful way to solve it, but it seems to work. Let me know if this solves your issue. |
I'm having the same issue. In my project I have routing-controllers package which currently has outdated dependency of I would argue that |
I have the same issue, I get the warning and the validate don' t return any ValidationError. I also I have confirmed by searching the node_modules folder that only one version has been installed, and the node_modules has been flattened. npm v6.4.1 tried the command thanks |
Ok, I got it working! For some reason it does not work when used with typedi container. // ...
import { Container } from 'typedi';
import * as ClassValidator from 'class-validator';
ClassValidator.useContainer(Container);
// ... |
Thanks, I had the same issue. Then, using Setting the same version of class-validator used in C in my packages in both A and B solved the issue |
Hello again. Seems that even with one single version of class-validator, the issue still exists. Any indications about why this could be the case ? Edit: Ok, after 2 hours trying to fix this, we realized that Typedi was not going to help (we did not manage to make it work). Our use case is really simple: we use lerna. And as such, we don't have a flattened 'node_modules' during development. class-validator should really support such a use case out of the box |
Hi, I reproduced the problem Here is the bug repo link. It's a nestjs project using class-validator to validate inputs. Bug condition:
The key point Code thoughts? |
@RDeluxe for the Lerna case hoisting the related packages worked for us. Have you tried this? Added the packages we want to hoist to the Lerna.json as below:
|
Im getting this error using the ValidationPipe from Nestjs.
|
Any update for this issue? I have same problem with only 1 version of class-validator:
|
Same using NestJS (6.1.1):
|
Same issue, I found the problem is there are really have multiple modules inside the node_modules folder, but shows
I currently use lerna to manage it, it seems copy the sub nodes_modules to the folder instead of flatten to install. |
I think lerna caused problem with it. |
I spent a lot of time on this recently, and wanted to share my insights. This issue is very inconvenient, to say the least. TLDR: |
Having the same message here, validation not working: $ npm ls class-validator Trying to use sequelize instead of typeorm. Any thoughts? |
Hi, I have the same issue using a Lerna monorepo that includes a NestJS API and a custom module which both rely on class-validator. I tried removing the class-validator dependency from the NestJS API project, and instead exposing it from my module. When I publish and consume my custom module in the NestJS API, this seems to work. HOWEVER, when I'm developing using
Running
Obviously this is super-annoying as I can't develop my module and API in tandem. I haven't been able to get any of the above suggestions/workarounds to work yet. Anyone succeeded with the Lerna/NestJS/Custom module scenario? |
@danloiterton Use deps hoisting. |
Thanks for the response, @19majkel94. I had half-heartedly looked into this. I gave With some more detailed research, trial and error, I now have it working! For anyone else with this scenario, I ended up using yarn workspaces in conjunction with lerna. This switch caused a whole bunch of "Duplicate identifier" errors during the typescript build process. These seemed to be caused by Hope that helps someone - it's been driving me nuts! o_O |
aha, thanks. Hi @rfgamaral, might you provide me a code sample that reproduces the issue? |
I've created the env. Testing. |
So, the problem is still within I think it makes sense to open a PR by moving |
@satanTime I've looked through Any chance you could go over there and create a new issue yourself? Maybe as a mantainer of this you'll have better luck? Thank you for researching this. |
I'm not a mantainer, I'm a contributor, we need to ask @vlapo. Anyway I'll open a ticket and add references to other packages that use |
Added a comment here: MichalLytek/type-graphql#366 |
I'm using Yarn so I've temporarily fixed like this: "resolutions": {
"class-validator": "0.12.0-rc.0"
} |
However, I'm not sure about one thing... I'm using |
One easy way to get rid of this warning is to add one validation config somewhere in your code.
|
@satanTime I just tested
Thoughts? |
Very interesting 🧠, could you share the code base with me? |
Added you as a collaborator to a private repo... |
Hi @vlapo, I was able to reproduce the issue. I'll create PR with the fix soon, I'll try today but probably this week. |
Okay, it was easy. (@rfgamaral you can delete me from the repo). the error message comes from https://github.com/typestack/class-validator/blob/master/src/validation/ValidationExecutor.ts#L49 @rfgamaral, I would say , simply add validation rules to your model. @vlapo, not sure if we should do anything here. If you have an idea - let me know, I'm always glad to contribute. |
But I'm using
I'm not sure what you mean, am I not doing that already with |
@rfgamaral, I've not seen it in your repo. let's go back to the "chat" :) |
Sorry everyone, and sorry @satanTime for wasting your time. There was no problem, I made a bit mistake (kinda tired) and it was my problem all along. Everything is great, please keep up the good work :) |
I hate this misleading warn message but for now it is our only indication about missing metadata in prod (whatever it is because of no validation rules or more than one class-validator libs installed). |
Thanks @satanTime for your quick reactions :) |
Hi guys, sharing my experience on this...stuck for 2-3 days, now I got a solution that words for my scenario. I got the ~ error message when trying to validate models via Jest (unit test) in a NestJS project. The NestJS project references models from a Lerna monorepo (relative path - and NestJS is not part of the monorepo). Jest references packages in the monorepo via
I think, the reason I am getting the error message is because the model files resolve 'class-validator' by traversing up its directory path. So, even when if i hoist dependencies to the root Lerna directory, it does not work. Solution: Specifically, tell Jest know how to resolve 'class-validator' by adding an entry to
Hope this helps someone with similar scenario. |
Why the hell was this issue closed? It is still there... |
Hello to your house too, @Syy0n. Steps to reproduction please. |
For me it happens in authorizationChecker @satanTime. const expressApp: Application = createExpressServer({
//..
authorizationChecker: async (action: Action, roles: string[]) => {
const user = await connection.getMongoRepository(User).find();
console.log(user);
return true;
},
//...
}); This happens me when i call the User model or any other class that imports the 'class-validator'. |
Hi @glikaj, the first thing is please verify you use |
Thank you @satanTime, update to |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi. Can anyone describe what exactly is this?
I have like 4 of those messages
The text was updated successfully, but these errors were encountered: