You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue manifests when all models are in a package that we used to share our models. This package is built with 'tsc' and installed in our project.
When importing a model that is already used by another module, the first module needs to be used in the second module also, an error occure that: OverwriteModelError: Cannot overwrite SubscriberEvent model once compiled.
install the package in your project using npm i 'path to the package'
import the models in your modules example: import { Event, MetaEvent } from '@beeinn/database-models';
use MongooseModule.forFeature
Expected behavior
the expected behavior is to load the models without problemes, if the model are already compiled non need to overwrite.
Package version
9.2.2 - 10.0.0
mongoose version
7.3.4
NestJS version
9.0.0
Node.js version
18.16.0
In which operating systems have you tested?
macOS
Windows
Linux
Other
OverwriteModelError: Cannot overwrite SubscriberEvent model once compiled.
at NativeConnection.Connection.model (/Users/x/Documents/bee/bff-it-app/node_modules/mongoose/lib/connection.js:1071:13)
at InstanceWrapper.useFactory [as metatype] (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/mongoose/dist/mongoose.providers.js:29:42)
at Injector.instantiateClass (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:354:55)
at callback (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:56:45)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at Injector.resolveConstructorParams (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:136:24)
at Injector.loadInstance (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:61:13)
at Injector.loadProvider (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:88:9)
at Injector.lookupComponentInImports (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:281:17)
at Injector.lookupComponentInParentModules (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:245:33)
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Current behavior
The issue manifests when all models are in a package that we used to share our models. This package is built with 'tsc' and installed in our project.
When importing a model that is already used by another module, the first module needs to be used in the second module also, an error occure that: OverwriteModelError: Cannot overwrite
SubscriberEvent
model once compiled.Example:
Module 1 : EventsModule
Module 2 : SubscribersEventModule
Minimum reproduction code
https://github.com/omarberrami/nest-mongoose-bug
Steps to reproduce
2 . npm i
Expected behavior
the expected behavior is to load the models without problemes, if the model are already compiled non need to overwrite.
Package version
9.2.2 - 10.0.0
mongoose version
7.3.4
NestJS version
9.0.0
Node.js version
18.16.0
In which operating systems have you tested?
Other
OverwriteModelError: Cannot overwrite
SubscriberEvent
model once compiled.at NativeConnection.Connection.model (/Users/x/Documents/bee/bff-it-app/node_modules/mongoose/lib/connection.js:1071:13)
at InstanceWrapper.useFactory [as metatype] (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/mongoose/dist/mongoose.providers.js:29:42)
at Injector.instantiateClass (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:354:55)
at callback (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:56:45)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at Injector.resolveConstructorParams (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:136:24)
at Injector.loadInstance (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:61:13)
at Injector.loadProvider (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:88:9)
at Injector.lookupComponentInImports (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:281:17)
at Injector.lookupComponentInParentModules (/Users/x/Documents/bee/bff-it-app/node_modules/@nestjs/core/injector/injector.js:245:33)
The text was updated successfully, but these errors were encountered: