Giter Site home page Giter Site logo

Nest can't resolve dependencies of the MikroOrmCoreModule (Symbol(mikro-orm-module-options), ?). Please make sure that the argument ModuleRef at index [1] is available in the MikroOrmCoreModule context. about nestjs HOT 7 CLOSED

mikro-orm avatar mikro-orm commented on September 2, 2024
Nest can't resolve dependencies of the MikroOrmCoreModule (Symbol(mikro-orm-module-options), ?). Please make sure that the argument ModuleRef at index [1] is available in the MikroOrmCoreModule context.

from nestjs.

Comments (7)

rynti avatar rynti commented on September 2, 2024 9

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.

EduVencovsky avatar EduVencovsky commented on September 2, 2024 1

@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.

hcharley avatar hcharley commented on September 2, 2024

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.

evantrimboli avatar evantrimboli commented on September 2, 2024

Looks like a dupe of: #27

from nestjs.

hcharley avatar hcharley commented on September 2, 2024

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.

B4nan avatar B4nan commented on September 2, 2024

If you are using nest 8 then it is a dup of #27. If not, provide full repro.

from nestjs.

ruscon avatar ruscon commented on September 2, 2024

for pnpm in the .npmrc need to add

public-hoist-pattern[]=@mikro-orm/*

from nestjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.