lucasrochagit / nest-mongo-query-parser

A MongoDB query string parser to be used in applications developed with NestJS.
Apache License 2.0
12 stars 8 forks source link

I got an error "Cannot find module 'nest-mongo-query-parser' or its corresponding type declarations." #13

Closed ykh closed 1 year ago

ykh commented 1 year ago

I've decided to use the package in my project, but in the first step I got this error "Cannot find module 'nest-mongo-query-parser' or its corresponding type declarations.". What can be its cause?

The way to import:

...
import { MongoQuery, MongoQueryModel } from 'nest-mongo-query-parser';
...

My tsconfig:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false
  }
}
lucasrochagit commented 1 year ago

Hello, @ykh.

I figured it might have been a bug related to the latest library version, however when creating a test project from scratch with the NestJS v9.2.0 CLI using node v18.15.0, I didn't get this error message.

The tsconfig.json file from your project is ok. It doesn't seem to me to be a problem with the project's tsconfig.json configuration, as it is the default configuration for projects created with the NestJS CLI. Also, the import of the objects is also correct.

Does this error prevent your project from running or is it just a warning from the IDE you use? If it's just an IDE warning, there might be some conflict between the IDE's tsconfig and the project's tsconfig.

ykh commented 1 year ago

Hi @lucasrochagit Tnx for response.

I get the error in compile-time, so I can't run the project:

image

ykh commented 1 year ago

Hello @lucasrochagit No news about this issue? I still couldn't use the package.

lucasrochagit commented 1 year ago

Hello @ykh, sorry 'bout the delay. I was busy solving some work problems.

I generate many projects using a few versions of nestjs and nodejs, and it's okay for me. No errors.

Let me ask you some questions:

Did you tried to install older versions of this library in your project? Or you just tried with the latest version?

Is your project an open source project? Can you share it with me, so I can try by myself?

ykh commented 1 year ago

Hello again @lucasrochagit.

That's fine. I hope we can find a solution.

Unfortunately I can't share project with you (it's not open source). Although I can share some parts of code that it supposed to be related to this issue.

package.json

  "dependencies": {
...
    "nest-mongo-query-parser": "^1.0.10",
...
  },

media.controller.ts

import {
  ClassSerializerInterceptor,
  Controller,
  UseInterceptors,
} from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';
import { MongoQuery, MongoQueryModel } from 'nest-mongo-query-parser';
import { MessagesNames } from '../../messages/messages-names';
import { CreateMediumReqDto } from './dto/requests/createMedium.req.dto';
import { GetMediaReqDto } from './dto/requests/getMedia.req.dto';
import { MediaService } from './media.service';

@Controller('media')
export class MediaController {
  constructor(private readonly mediaService: MediaService) {}

  @MessagePattern({ cmd: MessagesNames.CREATE_MEDIUM })
  @UseInterceptors(ClassSerializerInterceptor)
  async createMedium(createMediumReqDto: CreateMediumReqDto) {
    return this.mediaService.createMedium(createMediumReqDto);
  }

  @MessagePattern({ cmd: MessagesNames.GET_MEDIA })
  @UseInterceptors(ClassSerializerInterceptor)
  async getMedia(getMediaReqDto: GetMediaReqDto) {
    return this.mediaService.getMedia(getMediaReqDto);
  }

  async tempMethod(@MongoQuery() d: MongoQueryModel) {}
}

node version: 18.12.1

lucasrochagit commented 1 year ago

@ykh can you try to use the version v1.0.9 from lib, and check if the problem persists?

ykh commented 1 year ago

@lucasrochagit I tried v1.0.9 but I got the same error. It's kinda weird issue!

lucasrochagit commented 1 year ago

@ykh yes, I agree.

I would like to ask you to try something different.

  1. Can you try to clone and run this project here, and see if the problem persists? template-nestjs-with-mongodb.
  2. Can you create a new nest project, try to install the lib and see if the problem persists?
ykh commented 1 year ago

@lucasrochagit Hello again,

It works on template-nestjs-with-mongodb! I'll compare them to look for a clue. If you have some anticipates please tell me.

Thanks

lucasrochagit commented 1 year ago

@ykh, I was thinking that it could be a package publishing problem, or some problem with the typescript interface that exports these classes. But because the lib works in other projects, I believe it could be some other specific problem.

About your project, I can suggest you to do another things, such as:

ykh commented 1 year ago

@lucasrochagit Thank you for your suggestions. I have tried all of them and got same result!

Yesterday I figured out the issue is relates to my docker environment because it works out of container! I ran template-nestjs-with-mongodb project inside the container and it was fine!

Well, we have a kind of a new clue but it's still weird for me! It only happens for this package. really why?! 😆

I'm going to check these things, maybe will be helpful:

lucasrochagit commented 1 year ago

@ykh yes, it seems a little strange that only this package has this error. But if you look at the source code, there's nothing in the code that needs any special access or permissions. Only the query is intercepted and modified based on the informed parameters.

I can suggest you to validate the library directory in node_modules, and check the following files:

Please keep me informed if you have news about it.