Comments (7)
Preface
I encountered this error and was stuck for a while, but recently figured it out and wanted to post my issue+solution in case someone else stumbles on it.
The issue
The core issue was that I had multiple installations of nestjs, although they had the same version, but just in different folders. And then the mikro-orm packages were accessing a different installation of NestJS than my application. I think this led to the error that ModuleRef couldn't be found, because the ModuleRef that the mikro-orm modules wanted to use is from a different NestJS installation than the one that my application was actually providing.
The reason it was so hard to figure out is that I am using yarn v1 workspaces and my application is just a single package within the workspace. And my package within the workspace had (for some unknown reason) its own installation of NestJS, whereas mikro-orm was properly hoisted (hoisting means the module is installed in the root of the workspace instead of just the individual package) and installed in the root of my workspace, in addition to the aforementioned separate installation of NestJS that was also hoisted and installed in the root of my workspace.
So the structure looked like this:
/ (root of my yarn workspace)
node_modules/ (hoisted node modules)
@nestjs/... (hoisted version of @nestjs)
@mikro-orm/... (hoisted version of @mikro-orm packages, they access the
hoisted @nestjs packages from this same directory)
packages/
my-subpackage/ (this is my own package)
node_modules/
@nestjs/... (this is a different installation of the @nestjs packages,
that are actually used by my application code)
src/
... (my application code)
package.json (the package.json for this my-subpackage)
package.json (the package.json for the whole yarn workspace)
yarn.lock (the yarn lockfile for the whole workspace)
And the confusing part was that the yarn.lock indicated that only a single version of the @nestjs/... packages were installed. Only after manually checking the directories I figured this out.
How I solved it
I could finally solve it by setting the nohoist
attribute in the package.json within my-subpackage, to force yarn to not hoist the nestjs and mikro-orm packages.
So the package.json inside of my-subpackage finally looked like this:
{
"name": "my-subpackage",
...
"workspaces": {
"nohoist": ["@mikro-orm/**", "@nestjs/**"]
}
}
Afterwards, it was important to remove the node_modules directories and remove the existing yarn.lock file, so that yarn actually applies the nohoist rules.
Additionally, in case you encounter this error but aren't using yarn workspaces, my advice is just to go through the node_modules folders and figure out if there are any multiple versions of @nestjs/... or @mikro-orm/... packages installed, and if so, you'll have to figure out why and how to force NPM/Yarn (or whichever package manager of your choice) to only install a single version of these packages.
Good luck!
from nestjs.
@hcharley what do you mean by "starting fresh" ? What exactly you did to make it work? I'm having the same issue and upgrading to v4.3 doesn't solve it.
from nestjs.
I console logged out the options I passed into the MikroOrmModule static methods I used:
forFeature [ [class Resource extends BaseEntity] ]
forRoot {
dbName: 'project',
user: 'project',
host: 'localhost',
port: 5432,
password: undefined,
type: 'postgresql',
autoLoadEntities: true,
migrations: { migrationsList: [] }
}
from nestjs.
Looks like a dupe of: #27
from nestjs.
It's a strange thing, but I was able to overcome this issue by starting my feature branch fresh. There was probably some implemenation quirk I ran into.
I'm happy to close this issue (although I may open it back up if I come across it again).
from nestjs.
If you are using nest 8 then it is a dup of #27. If not, provide full repro.
from nestjs.
for pnpm
in the .npmrc
need to add
public-hoist-pattern[]=@mikro-orm/*
from nestjs.
Related Issues (20)
- Error when trying to query an entity from the repository HOT 3
- How can I take some actions after it successfully connects or fails? HOT 1
- Cannot persist an entity with a 1-to-1 reference to another entity HOT 5
- Cannot persist Read-Only association HOT 3
- Cannot get `@UseRequestContext` to work in a REQUEST scoped BullMQ processor HOT 4
- Populating Nested Field returns the wrong number of associated entities HOT 5
- Relations not working in nestjs HOT 6
- Issue when running tests after upgrading to 5.2.2
- Bump version, compatible with MikroORM V6 HOT 6
- Nestjs, mikro-orm and postgres can't generate table automatically HOT 2
- vitest + mikroorm collection error HOT 4
- findByCursor method not working on sqlite HOT 1
- Testing with multiple testing modules in NestJS and Jest leads to an error during metadata discovery HOT 2
- Issues running Mikro-ORM with NestJS on Vercel platform HOT 1
- MikroOrmMiddleware not found in e2e tests
- feat: add Transactional Decorator HOT 1
- How to listen to connection status?
- Nest cannot export a provider/module that is not a part of the currently processed module (MikroOrmCoreModule). Please verify whether the exported MongoMikroORM is available in this particular context.
- Allow specifying .fork() options for Request-Scoped EntityManager in the MikroOrmModule
- Using multiple databases hustle
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nestjs.