I created a migration for an entity in Mikro Orm. After that, i modified the entity and ran the migrations again. Now nestjs keeps giving me this error.
This was my entity.
#Entity()
export class Task extends BaseEntity<Task, 'id'> {
#PrimaryKey()
id: number;
#Property()
name: string;
#Property()
description: string;
}
I created initial migration with npx mikro-orm migration:create --initial. After that i modified my entity to this:
#Entity()
export class Task extends BaseEntity<Task, 'id'> {
#PrimaryKey()
id: number;
#Property()
name: string;
#Property()
description: string;
#Enum(() => TaskStatus)
status: TaskStatus = TaskStatus.OPEN;
}
export enum TaskStatus {
OPEN = 'OPEN',
IN_PROGRESS = 'IN_PROGRESS',
DONE = 'DONE',
}
After that, I ran two commands npx mikro-orm migration:create & npx mikro-orm migration:up.
Now NestJs keeps giving me this error.
[Nest] 13528 - 02/06/2021, 6:59:14 pm [NestFactory] Starting Nest application...
[Nest] 13528 - 02/06/2021, 6:59:14 pm [InstanceLoader] MikroOrmModule dependencies initialized +43ms
[Nest] 13528 - 02/06/2021, 6:59:14 pm [InstanceLoader] ConfigHostModule dependencies initialized +1ms
[Nest] 13528 - 02/06/2021, 6:59:14 pm [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 13528 - 02/06/2021, 6:59:14 pm [InstanceLoader] ConfigModule dependencies initialized +0ms
[Nest] 13528 - 02/06/2021, 6:59:14 pm [ExceptionHandler] Duplicate entity names are not allowed: Task +409ms
MetadataError: Duplicate entity names are not allowed: Task
at Function.duplicateEntityDiscovered (C:\dev\nodejs\nestjs\sandbox\node_modules\#mikro-orm\core\errors.js:151:16) at MetadataValidator.validateDiscovered (C:\dev\nodejs\nestjs\sandbox\node_modules\#mikro-orm\core\metadata\MetadataValidator.js:40:42)
at MetadataDiscovery.findEntities (C:\dev\nodejs\nestjs\sandbox\node_modules\#mikro-orm\core\metadata\MetadataDiscovery.js:81:24)
at processTicksAndRejections (node:internal/process/task_queues:93:5)
at async MetadataDiscovery.discover (C:\dev\nodejs\nestjs\sandbox\node_modules\#mikro-orm\core\metadata\MetadataDiscovery.js:34:9)
at async Function.init (C:\dev\nodejs\nestjs\sandbox\node_modules\#mikro-orm\core\MikroORM.js:42:24)
at async Injector.instantiateClass (C:\dev\nodejs\nestjs\sandbox\node_modules\#nestjs\core\injector\injector.js:290:37)
at async callback (C:\dev\nodejs\nestjs\sandbox\node_modules\#nestjs\core\injector\injector.js:42:30)
at async Injector.resolveConstructorParams (C:\dev\nodejs\nestjs\sandbox\node_modules\#nestjs\core\injector\injector.js:114:24)
at async Injector.loadInstance (C:\dev\nodejs\nestjs\sandbox\node_modules\#nestjs\core\injector\injector.js:46:9)
I also had this issue and I knew I didn't have a duplicate model name. The problem occurred after I had moved a model to a different directory.
The resolution was to clear the dist build folder and the temp metadata folders.
UPDATE
After investigation, the code can be run perfectly. There maybe some problems on the node_modules where some incomplete/incompatible packages exist.
The solution is to remove node_modules and reinstall again.
The steps you do is the following:
create a Task class
create migration file
modify the Task class
create migration file again
do the migration
If you modify the Task class without running migration command before, you will end up having 2 migration files with create task table command because mikro does not have any references of task table before any migration happened.
You can check the SQL in both migration files, it should be create table task xxx.
Therefore, there is a way to solve it:
delete the 2nd migration file first
run npx mikro-orm migration:up to create task table on DB without enum
run npx mikro-orm migration:create.
Right now, mikro has references of the task table and know that you want to alter table so the SQL in migration will be alter table task instead of create table
run npx mikro-orm migration:up to alter task table on DB with enum
Related
I'm trying to run the command 'flutter packages pub run build_runner build' and I'm getting an error as return, can someone help me ??
This is my code
import 'package:chopper/chopper.dart';
part 'post_api_service.chopper.dart';
#ChopperApi(baseUrl: 'https://jsonplaceholder.typicode.com/posts')
abstract class PostApiService extends ChopperService {
#Get()
Future<Response> getPosts();
#Get(path: '/{id}')
Future<Response> getPost(#Path('id') int id);
#Post()
Future<Response> postPost(
#Body() Map<String, dynamic> body,
);
}
This is the return
PS C:\srs\innovation\chopper\chopper_api> flutter packages pub run build_runner build
[INFO] Generating build script...
[INFO] Generating build script completed, took 414ms
[WARNING] Invalidated precompiled build script due to missing asset graph.
[INFO] Precompiling build script......
[INFO] Precompiling build script... completed, took 1.1s
[SEVERE]
type 'Null' is not a subtype of type 'String' in type cast
pub finished with exit code 78
PS C:\srs\innovation\chopper\chopper_api>
Just run the below command:
flutter packages pub run build_runner build --delete-conflicting-outputs
My nestjs app starts to blow up pointing to AXIOS_INSTANCE_TOKEN error and request for the module containing AXIOS_INSTANCE_TOKEN to be imported... the thing is the only module using Axios is HttpModule and it was imported from the start. this is what I have:
the error:
] [Nest] 94322 - 02/04/2021, 12:16:31 PM [Genysis Gateway] Start Gateway
[0] [Nest] 94322 - 02/04/2021, 12:16:32 PM [NestFactory] Starting Nest application...
[0] [Nest] 94322 - 02/04/2021, 12:16:32 PM [InstanceLoader] RavenModule dependencies initialized
[0] [Nest] 94322 - 02/04/2021, 12:16:32 PM [InstanceLoader] MsConnectorModule dependencies initialized
[0] [Nest] 94322 - 02/04/2021, 12:16:32 PM [InstanceLoader] ChatModule dependencies initialized
[0] [Nest] 94322 - 02/04/2021, 12:16:32 PM [InstanceLoader] HttpModule dependencies initialized
[0] [Nest] 94322 - 02/04/2021, 12:16:32 PM [InstanceLoader] HttpModule dependencies initialized
[0] [Nest] 94322 - 02/04/2021, 12:16:32 PM [InstanceLoader] HttpModule dependencies initialized
[0] [Nest] 94322 - 02/04/2021, 12:16:32 PM [InstanceLoader] ConfigHostModule dependencies initialized
[0] [Nest] 94322 - 02/04/2021, 12:16:32 PM [ExceptionHandler] Nest can't resolve dependencies of the HttpService (?). Please make sure that the argument AXIOS_INSTANCE_TOKEN at index [0] is available in the AppModule context.
[0]
[0] Potential solutions:
[0] - If AXIOS_INSTANCE_TOKEN is a provider, is it part of the current AppModule?
[0] - If AXIOS_INSTANCE_TOKEN is exported from a separate #Module, is that module imported within AppModule?
[0] #Module({
[0] imports: [ /* the Module containing AXIOS_INSTANCE_TOKEN */ ]
[0] })
THIS IS THE APP MODULE:
......
#Module({
imports: [
RavenModule,
ConfigModule.forRoot({
isGlobal: true,
load: [configuration],
}),
HttpModule.register({
timeout: 5000,
maxRedirects: 5,
}),
AuthModule,
UserModule,
.......
I noticed that the three references to HttpModule initialized ok. Also, I have a check and the two other modules with HttpModules have correctly imported HttpModule in the Module and the injected the HttpService in the Service.
I also noticed that the build died while building ConfigModule...not sure what that means?.... I have also deleted node_modules and run npm I twice and upgrade my nestjs/common from 7.5.1 to 7.6.11 all to no avail.
I would really appreciate any insights on this! Thanks in advance.
Apparently I somehow included HttpService in the app module as a provider and exported it also. Removing both entries resolved the problem.
I had this issue. your appModule is Ok all you need to do is to remove the HttpService from the provider and import HttpModule in order to have HttpService provider available to use.
also see https://docs.nestjs.com/techniques/http-module#getting-started
Havin problem to run nestjs app.
Current ecosystem:
- Windows 10
- node ver: v12.10.0
- npm ver: 6.10.3
- nestjs ver: 6.14.2
Steps to reproduce:
git clone https://github.com/gandra/nestjs-task-managament
cd nestjs-task-managament
npm i
npm run start
Receiving following error:
CustomRepositoryCannotInheritRepositoryError: Custom entity repository TaskRepository cannot inherit Repository class without entity being set in the #EntityRepository decorator.
at new CustomRepositoryCannotInheritRepositoryError (C:\learn\node\nestjs-task-managament\node_modules\typeorm\error\CustomRepositoryCannotInheritRepositoryError.js:10:28)
at EntityManager.getCustomRepository (C:\learn\node\nestjs-task-managament\node_modules\typeorm\entity-manager\EntityManager.js:607:23)
at Connection.getCustomRepository (C:\learn\node\nestjs-task-managament\node_modules\typeorm\connection\Connection.js:365:29)
at getCustomRepository (C:\learn\node\nestjs-task-managament\node_modules\#nestjs\typeorm\dist\typeorm.providers.js:15:68)
at InstanceWrapper.useFactory [as metatype] (C:\learn\node\nestjs-task-managament\node_modules\#nestjs\typeorm\dist\typeorm.providers.js:20:24)
at Injector.instantiateClass (C:\learn\node\nestjs-task-managament\node_modules\#nestjs\core\injector\injector.js:291:55)
at callback (C:\learn\node\nestjs-task-managament\node_modules\#nestjs\core\injector\injector.js:75:41)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Injector.resolveConstructorParams (C:\learn\node\nestjs-task-managament\node_modules\#nestjs\core\injector\injector.js:116:24)
at async Injector.loadInstance (C:\learn\node\nestjs-task-managament\node_modules\#nestjs\core\injector\injector.js:79:9)
Seems that following 2 things fixed issue.
First I have changed TaskRepository annotation from #EntityRepository() to #EntityRepository(Task). After that fix I have got error EntityMetadataNotFound.
Then I have changed TypeOrm entities con in file src/config/typeorm.config.ts and replaced entities: [__dirname + '/../**/*.entity.ts'], with entities: [__dirname + '/../**/*.entity.{js,ts}'],.
I just followed the documentation and attached prisma to my nest project. The problem is, when I run yarn start:dev it populates the graphql.options.ts with some unknown schema and throws the following error:
[nodemon] starting `ts-node -r tsconfig-paths/register src/main.ts`
[Nest] 50392 - 12/24/2018, 10:08:57 PM [NestFactory] Starting Nest application...
[Nest] 50392 - 12/24/2018, 10:08:57 PM [InstanceLoader] AppModule dependencies initialized +43ms
[Nest] 50392 - 12/24/2018, 10:08:57 PM [InstanceLoader] PrismaModule dependencies initialized +0ms
[Nest] 50392 - 12/24/2018, 10:08:57 PM [InstanceLoader] UsersModule dependencies initialized +1ms
[Nest] 50392 - 12/24/2018, 10:08:57 PM [InstanceLoader] GraphQLModule dependencies initialized +0ms
(node:50392) UnhandledPromiseRejectionWarning: Error: Interface field Vehicle.wheels expects type Int but Car.wheels is type String.
Interface field argument Vehicle.stuff(a:) expects type Int but Car.stuff(a:) is type String.
at assertValidSchema (/Users/pubudu/Projects/nest-prisma-sample/node_modules/graphql/type/validate.js:71:11)
at assertValidExecutionArguments (/Users/pubudu/Projects/nest-prisma-sample/node_modules/graphql/execution/execute.js:146:35)
at executeImpl (/Users/pubudu/Projects/nest-prisma-sample/node_modules/graphql/execution/execute.js:67:3)
at Object.execute (/Users/pubudu/Projects/nest-prisma-sample/node_modules/graphql/execution/execute.js:62:229)
at Object.generateSchemaHash (/Users/pubudu/Projects/nest-prisma-sample/node_modules/apollo-server-core/src/utils/schemaHash.ts:11:18)
at new ApolloServerBase (/Users/pubudu/Projects/nest-prisma-sample/node_modules/apollo-server-core/src/ApolloServer.ts:299:23)
at new ApolloServer (/Users/pubudu/Projects/nest-prisma-sample/node_modules/apollo-server-express/src/ApolloServer.ts:70:1)
at GraphQLModule.<anonymous> (/Users/pubudu/Projects/nest-prisma-sample/node_modules/#nestjs/graphql/dist/graphql.module.js:118:33)
at Generator.next (<anonymous>)
at fulfilled (/Users/pubudu/Projects/nest-prisma-sample/node_modules/#nestjs/graphql/dist/graphql.module.js:16:58)
(node:50392) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:50392) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Here's the sample code:
https://github.com/THPubs/nest-prisma-sample
Any idea what's happening?
The issues is with the GraphQLOptions. In there, according to the examples, I have defined the typePaths as follows:
typePaths: ['./**/*.graphql'],
It looks like this gets all the graphql files in the project even from the node_modules folder. So, to import exactly the file I want, I used the following:
typePaths: ['./src/prisma/prisma-types.graphql'],
I created a microservice architecture using JHipster. I am using the jhipster-registry v2.8.0. I renamed the 'dev' profile to 'devdmi' because I will have many 'dev' profiles. It is working OK using the "dev,native" profiles for the jhipster-registry and each microservice including it's application-devdmi.yml / boostrap-devdmi.yml files.
I tried to convert this configuration over to using a Git repo. I built my Git repo with .yml files, but I'm not exactly sure of the configuration to use. At the moment I've got:
MyConfig/app1/MyApp1-devdmi.yml
MyConfig/app2/MyApp2-devdmi.yml
I also tried using:
MyConfig/MyApp1-devdmi.yml
MyConfig/MyApp2-devdmi.yml
In MyApp1, I renamed src/main/resources/config/application-devdmi.yml to application-devdmi.yml.bak hoping it would pick up the config from the jhipster-registry acting as a Spring Cloud Config Server.
In MyApp1, I have a bootstrap-devdmi.yml with:
spring:
application:
name: my-app-1
cloud:
config:
fail-fast: true
uri: http://admin:${jhipster.registry.password}#my.host.com:8761/config
name: MyApp1
profile: devdmi
label: master
The jhipster-registry starts up and shows it is connected to the Git repo by looking at the Configuration webpage.
MyApps1 doesn't start and throws an error about Liquibase not knowing which database to connect to:
2017-05-23 13:09:52.669 WARN 60704 --- [ main] o.s.boot.SpringApplication : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation /web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor' defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor]: Factory method 'transactionAdvisor' threw exception; nested exception is java.lang.NullPointerException)
2017-05-23 13:09:52.683 ERROR 60704 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Any ideas?