Skip to content
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

Issue while starting the application. #10

Open
neeteshraj opened this issue Nov 16, 2023 · 22 comments
Open

Issue while starting the application. #10

neeteshraj opened this issue Nov 16, 2023 · 22 comments

Comments

@neeteshraj
Copy link

I am running on Ubuntu 23. I have cloned the project and then ran
yarn infra
the docker containers are up and running successfully. But while trying to run the command
yarn start:dev i am getting connection error in mongo db.

Help me

Here is the error
[6:41:36 PM] File change detected. Starting incremental compilation...

[6:41:36 PM] Found 0 errors. Watching for file changes.

Tracing terminated
(node:53467) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)
TRACE [16/11/2023 09:56:38]: CacheMemory connected!
TRACE [16/11/2023 09:56:38]: Redis connected!

[sequelize] Executed (default): SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'cats' 4ms
[sequelize] Executed (default): SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'cats' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname; 3ms
TRACE [16/11/2023 09:56:38]: Sequelize connected!
(node:53467) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)

/home/nitesh-raj-khanal/Development/nestjs-microservice-boilerplate-api/node_modules/pino-mongodb/node_modules/mongodb/src/sdam/topology.ts:591
const timeoutError = new MongoServerSelectionError(
^
MongoServerSelectionError: Server selection timed out after 5000 ms
at Timeout._onTimeout (/home/nitesh-raj-khanal/Development/nestjs-microservice-boilerplate-api/node_modules/pino-mongodb/node_modules/mongodb/src/sdam/topology.ts:591:30)
at listOnTimeout (node:internal/timers:573:17)
at processTimers (node:internal/timers:514:7)

Screenshot from 2023-11-16 18-47-45

@mikemajesty
Copy link
Owner

Try connecting to a DBMS of your choice and see if the same error occurs.

@neeteshraj
Copy link
Author

i am trying to connect to mongodb and the error occurs.

@neeteshraj
Copy link
Author

also there is this error when running yarn start:dev

[2:52:42 PM] Starting compilation in watch mode...

src/infra/logger/service.ts:142:7 - error TS2322: Type 'Logger' is not assignable to type 'Logger'.
Type 'Logger' is not assignable to type 'LoggerExtras'.
Types of property 'onChild' are incompatible.
Type 'OnChildCallback<import("/home/nitesh/Development/nestjs-microservice-boilerplate-api/node_modules/pino/pino").LoggerOptions>' is not assignable to type 'OnChildCallback<import("/home/nitesh/Development/nestjs-microservice-boilerplate-api/node_modules/pino-http/node_modules/pino/pino").default.LoggerOptions>'.
Types of parameters 'child' and 'child' are incompatible.
Type 'Logger<LoggerOptions & ChildOptions>' is not assignable to type 'Logger<LoggerOptions & ChildLoggerOptions>'.
Type 'Logger<LoggerOptions & ChildOptions>' is not assignable to type 'LoggerExtras<LoggerOptions & ChildLoggerOptions>'.
The types returned by 'child(...)' are incompatible between these types.
Type 'Logger<LoggerOptions & ChildOptions & ChildOptions>' is not assignable to type 'Logger<LoggerOptions & ChildLoggerOptions & ChildOptions>'.
Type 'Logger<LoggerOptions & ChildOptions & ChildOptions>' is not assignable to type 'LoggerExtras<LoggerOptions & ChildLoggerOptions & ChildOptions>'.
Types of property 'on' are incompatible.
Type '<Opts = LoggerOptions & ChildOptions & ChildOptions>(event: "level-change", listener: LevelChangeEventListener<...>) => Logger<...>' is not assignable to type '<Opts = LoggerOptions & ChildLoggerOptions & ChildOptions>(event: "level-change", listener: LevelChangeEventListener) => LoggerExtras<...>'.
Types of parameters 'listener' and 'listener' are incompatible.
Types of parameters 'logger' and 'logger' are incompatible.
Type 'Logger<LoggerOptions & ChildOptions & ChildOptions>' is not assignable to type 'Logger'.
Type 'Logger<LoggerOptions & ChildOptions & ChildOptions>' is not assignable to type 'CustomLevelLogger'.

142 logger: pinoLogger,
~~~~~~

node_modules/pino-http/index.d.ts:26:5
26 logger?: pino.Logger | undefined;
~~~~~~
The expected type comes from property 'logger' which is declared here on type 'Options<IncomingMessage, ServerResponse>'

src/modules/user/module.ts:40:15 - error TS2322: Type 'Model<unknown, unknown, unknown, {}, Document<unknown, unknown, unknown> & Omit<Required<{ _id: unknown; }>, never>, UserDocument>' is not assignable to type 'MongoRepositoryModelSessionType<PaginateModel<UserDocument, {}, {}>>'.
Property 'paginate' is missing in type 'Model<unknown, unknown, unknown, {}, Document<unknown, unknown, unknown> & Omit<Required<{ _id: unknown; }>, never>, UserDocument>' but required in type 'PaginateModel<UserDocument, {}, {}>'.

40 const repository: MongoRepositoryModelSessionType<PaginateModel> = connection.model<
~~~~~~~~~~

node_modules/mongoose-paginate-v2/index.d.ts:104:5
104 paginate(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105 query?: FilterQuery,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
110 ) => void
~~~~~~~~~~~~~~~
111 ): Promise<PaginateResult<PaginateDocument<T, TMethods, O>>>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'paginate' is declared here.

src/modules/user/module.ts:43:22 - error TS2345: Argument of type 'Schema<User, Model<User, any, any, any, Document<unknown, any, User> & User & Required<{ _id: string; }>, any>, {}, {}, {}, {}, DefaultSchemaOptions, User, Document<...> & ... 1 more ... & Required<...>>' is not assignable to parameter of type 'Schema<UserDocument, any, any, {}, any, any, any, UserDocument | ({ createdAt: NativeDate; updatedAt: NativeDate; } & Document<any, any, any> & UserEntity), Document<...> & ((FlatRecord<...> & { ...; }) | (FlatRecord<...> & { ...; }))>'.
The types of 'obj.login' are incompatible between these types.
Type 'SchemaDefinitionProperty<string, User>' is not assignable to type 'SchemaDefinitionProperty<string, UserDocument>'.
Type 'SchemaTypeOptions<string, User>' is not assignable to type 'SchemaDefinitionProperty<string, UserDocument>'.
Type 'SchemaTypeOptions<string, User>' is not assignable to type 'SchemaTypeOptions<string, UserDocument> | MixedSchemaTypeOptions'.
Type 'SchemaTypeOptions<string, User>' is not assignable to type 'SchemaTypeOptions<string, UserDocument>'.
Type 'User' is not assignable to type 'UserDocument'.

43 >(User.name, UserSchema);
~~~~~~~~~~

[2:52:48 PM] Found 3 errors. Watching for file changes.

@neeteshraj
Copy link
Author

@mikemajesty any solutions?

@mikemajesty
Copy link
Owner

Can you share your repo?

@neeteshraj
Copy link
Author

@neeteshraj
Copy link
Author

@mikemajesty can you address the issue here?

@mikemajesty
Copy link
Owner

There is a difference in some versions of the libraries and there should probably be a break changes between them. I advise you to use the same boilerplate versions. I will update and resolve these issues soon.

@nestjs/common": "^10.2.8"
"@nestjs/core": "^10.2.8",
"@nestjs/mongoose": "^10.0.2",

image

@mikemajesty
Copy link
Owner

This error happens from version 7 of mongoose.

@neeteshraj
Copy link
Author

even with the specified packages. i am still getting the error. this is my package.json {
"name": "nestjs-boilerplate-microservice-api",
"version": "1.13.0",
"description": "Nestjs boilerplate api",
"author": "mike.rodrigues.lima@gmail.com",
"private": true,
"license": "MIT",
"scripts": {
"prepare": "husky install",
"build": "nest build",
"start": "node dist/src/main",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"prettier": "prettier --write "src//*.ts" "test//.ts"",
"lint": "eslint "{src,test}/**/
.{ts,js}" --fix",
"test": "jest --config="./jest.config.ts" --detectOpenHandles",
"test:cov": "jest --coverage --detectOpenHandles && yarn make-badges",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"infra": "./scripts/mongo/start-replicaset.sh",
"scaffold": "./node_modules/@mikemajesty/microservice-crud/bin/microservice-crud",
"migration:create": "npx sequelize-cli migration:generate --name migration-skeleton",
"migration:run": "npx sequelize-cli db:migrate",
"make-badges": "istanbul-badges-readme"
},
"dependencies": {
"@nestjs/common": "^10.0.2",
"@nestjs/config": "^3.1.0",
"@nestjs/core": "^10.0.2",
"@nestjs/mongoose": "^10.0.2",
"@nestjs/platform-express": "^10.0.2",
"@nestjs/swagger": "^7.1.0",
"@opentelemetry/api": "^1.7.0",
"@opentelemetry/exporter-metrics-otlp-http": "^0.45.0",
"@opentelemetry/exporter-trace-otlp-proto": "^0.45.0",
"@opentelemetry/instrumentation-http": "^0.45.0",
"@opentelemetry/instrumentation-mongodb": "^0.37.0",
"@opentelemetry/instrumentation-pg": "^0.37.0",
"@opentelemetry/instrumentation-redis-4": "^0.35.4",
"@opentelemetry/resources": "^1.18.0",
"@opentelemetry/sdk-node": "^0.45.0",
"@opentelemetry/sdk-trace-web": "^1.18.0",
"@opentelemetry/semantic-conventions": "^1.18.0",
"axios": "^1.6.0",
"axios-better-stacktrace": "^2.1.5",
"axios-retry": "^3.9.0",
"body-parser": "^1.20.2",
"class-validator": "^0.14.0",
"colorette": "^2.0.19",
"convert-pino-request-to-curl": "^0.0.29",
"express-rate-limit": "^7.1.4",
"helmet": "^7.1.0",
"jsonwebtoken": "^9.0.0",
"luxon": "^3.4.0",
"mongoose": "^6.9.0",
"mongoose-paginate-v2": "^1.7.1",
"nestjs-convert-to-curl": "^0.0.22",
"node-cache": "^5.1.2",
"pg": "^8.10.0",
"pg-hstore": "^2.3.4",
"pino": "^8.5.0",
"pino-http": "^8.2.0",
"pino-mongodb": "^4.3.0",
"pino-pretty": "^9.1.0",
"redis": "^4.6.4",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.0",
"sequelize": "^6.35.0",
"sequelize-typescript": "^2.1.5",
"swagger-ui-express": "^5.0.0",
"ts-jest": "^29.1.1",
"uuid": "^9.0.0",
"zod": "^3.20.2"
},
"devDependencies": {
"@commitlint/cli": "^18.4.0",
"@commitlint/config-conventional": "^18.4.0",
"@mikemajesty/microservice-crud": "0.2.9",
"@nestjs/cli": "^10.0.2",
"@nestjs/schematics": "^10.0.2",
"@nestjs/testing": "^10.0.2",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^10.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^9.0.4",
"@semantic-release/npm": "^10.0.5",
"@semantic-release/release-notes-generator": "^11.0.4",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.46",
"@swc/jest": "^0.2.24",
"@types/express": "^4.17.13",
"@types/jest": "29.5.8",
"@types/jsonwebtoken": "^9.0.1",
"@types/luxon": "^3.2.0",
"@types/node": "^20.3.0",
"@types/sequelize": "^4.28.14",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-security": "^1.7.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-you-dont-need-lodash-underscore": "^6.13.0",
"husky": "^8.0.3",
"istanbul-badges-readme": "^1.8.5",
"jest": "^29.1.1",
"prettier": "^2.3.2",
"semantic-release": "^21.1.1",
"sequelize-cli": "^5.3.0",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-loader": "^9.2.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "4.1.1",
"typescript": "5.1.6"
}
} and this is the error [11:43:36 AM] Starting compilation in watch mode...

[11:43:42 AM] Found 0 errors. Watching for file changes.

TRACE [18/11/2023 02:58:44]: CacheMemory connected!
TRACE [18/11/2023 02:58:44]: Redis connected!

[sequelize] Executed (default): SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'cats' 3ms
[sequelize] Executed (default): CREATE TABLE IF NOT EXISTS "cats" ("id" UUID , "name" VARCHAR(255), "age" INTEGER, "breed" VARCHAR(255), "deletedAt" TIMESTAMP WITH TIME ZONE, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id")); 12ms
[sequelize] Executed (default): SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'cats' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname; 4ms
TRACE [18/11/2023 02:58:44]: Sequelize connected!

/home/nitesh/Development/nestjs-microservice-boilerplate-api/node_modules/mongodb/src/sdam/topology.ts:591
const timeoutError = new MongoServerSelectionError(
^
MongoServerSelectionError: Server selection timed out after 5000 ms
at Timeout._onTimeout (/home/nitesh/Development/nestjs-microservice-boilerplate-api/node_modules/mongodb/src/sdam/topology.ts:591:30)
at listOnTimeout (node:internal/timers:569:17)
at processTimers (node:internal/timers:512:7)

@neeteshraj
Copy link
Author

the docker containers are up and running successfully but i cannot even connect to the replicaset to my mongodb compass.

@mikemajesty
Copy link
Owner

I can't get the same error here on my machine, even in your project.

Print the terminal output of the "npm run infra" command

Screenshot from 2023-11-18 11-44-51

@vinhcv161
Copy link

vinhcv161 commented Nov 26, 2023

I also had connection problems.
Try changing "localhost" to "127.0.0.1" and run again.
I understand it shouldn't have made a difference, but it worked

@neeteshraj
Copy link
Author

even after changing localhost to 127.0.0.1 i am getting this error
Uploading Screenshot 2023-11-30 at 7.39.41 PM.png…

@hisyam-harun
Copy link

Me too when try run yarn start:dev

Screenshot 2023-12-01 at 09 18 39

Aside that, is there any sample microservices app that was using this boilerplate?

@mikemajesty
Copy link
Owner

mikemajesty commented Dec 1, 2023

@neeteshraj @vinhcv161 try this branch: branch

@mikemajesty
Copy link
Owner

@hisyam-harun

remove
"builder": "swc",
"typeCheck": true

{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "compilerOptions": {
    "deleteOutDir": true,
    "builder": "swc",
    "typeCheck": true
  }
}

nest-cli.json

@neeteshraj
Copy link
Author

@neeteshraj @vinhcv161 try this branch: branch

still not connected

@vinhcv161
Copy link

vinhcv161 commented Dec 3, 2023

Please, try it: (add for local singleton: directConnection=true)

MONGO

#FOR STANDALONE:
MONGO_URL=mongodb://127.0.0.1:27017/nestjs-microservice?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&directConnection=true&ssl=false
#FOR CLUSTER:
#MONGO_URL=mongodb://127.0.0.1:27081,127.0.0.1:27082,127.0.0.1:27083/nestjs-microservice?replicaSet=app&serverSelectionTimeoutMS=5000&connectTimeoutMS=5000

@vinhcv161
Copy link

Please, try it:

MONGO

#FOR STANDALONE: MONGO_URL=mongodb://127.0.0.1:27017/nestjs-microservice?replicaSet=app&serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&directConnection=true&ssl=false #FOR CLUSTER: #MONGO_URL=mongodb://127.0.0.1:27081,127.0.0.1:27082,127.0.0.1:27083/nestjs-microservice?replicaSet=app&serverSelectionTimeoutMS=5000&connectTimeoutMS=5000

@mikemajesty @neeteshraj

@accountsware
Copy link

I am having similar issue

Mongo connection error

I could connect to Mongo if I just use MONGO_URL=mongodb://admin:secret@127.0.0.1:27017 connection string but then users collection is not to be seen anywhere is in MongoDB

Mongo connected

@accountsware
Copy link

I am having similar issue

Mongo connection error

I could connect to Mongo if I just use MONGO_URL=mongodb://admin:secret@127.0.0.1:27017 connection string but then users collection is not to be seen anywhere is in MongoDB

Mongo connected

silly me, saw your new .env !! connection string - working now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants