Nest: Cannot find module

Created on 14 Jan 2019  路  6Comments  路  Source: nestjs/nest

Hello I have a class that I have created and put it in a custom folder in the src folder. It is not a nestjs module nor a provider just a helper class that I can instantiate and use. However when I run the app I got the following error:

[npm run start:dev

> [email protected] start:dev /Users/arsenegandote/Applications/js/rent-go
> nodemon

[nodemon] 1.18.9
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: /Users/arsenegandote/Applications/js/rent-go/src/**/*
[nodemon] starting `ts-node -r tsconfig-paths/register src/main.ts`
Error: Cannot find module './json.result.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
    at Function.Module._resolveFilename (/Users/arsenegandote/Applications/js/rent-go/node_modules/tsconfig-paths/lib/register.js:75:40)
    at Function.Module._load (internal/modules/cjs/loader.js:529:25)
    at Module.require (internal/modules/cjs/loader.js:658:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/Users/arsenegandote/Applications/js/rent-go/src/lib/api.controller.ts:1:1)
    at Module._compile (internal/modules/cjs/loader.js:722:30)
    at Module.m._compile (/Users/arsenegandote/Applications/js/rent-go/node_modules/ts-node/src/index.ts:439:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:733:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/Users/arsenegandote/Applications/js/rent-go/node_modules/ts-node/src/index.ts:442:12)
[nodemon] app crashed - waiting for file changes before starting...](url)

This is the class I am instantiating in a controller:

export class JsonResult<T> {
  readonly status: string;
  readonly data: T;

  constructor(status: string, data: T) {
    this.status = status;
    this.data = data;
  }
}

and my controller implements this abstract class:

export abstract class ApiController {
  failed(): void {
    throw new HttpException(
      {
        status: ApiStatus.FAILED,
        data: {},
      },
      HttpStatus.INTERNAL_SERVER_ERROR,
    );
  }

  notFound(): void {
    throw new HttpException(
      {
        status: HttpStatus.NOT_FOUND,
        data: [],
      },
      HttpStatus.NOT_FOUND,
    );
  }

  badRequest(message: string): void {
    throw new HttpException(
      {
        status: HttpStatus.BAD_REQUEST,
        data: {
          message,
        },
      },
      HttpStatus.BAD_REQUEST,
    );
  }

  success<T>(data: T): JsonResult<T> {
    return new JsonResult<T>(ApiStatus.SUCCESS, data);
  }
}

Most helpful comment

very rude

All 6 comments

Please, use StackOverflow for such questions.

very rude

@SamiHK we are using GitHub to track bugs, feature requests, and potential improvements. It's really difficult to keep GitHub clean and we don't have people that would spend their free time answering questions that shouldn't be located here. For support questions, we encourage people to use our Discord channel or StackOverflow.

@kamilmysliwiec
I have followed StackOverflow: https://stackoverflow.com/questions/53963007/error-while-running-nestjs-in-production-mode-cannot-find-module

Event correct answer was not able to solve this issue.
It was working correctly on the local environment but as soon as I hit npm run start:dev it shows the exact same error the above person was talking about.

Maybe you can train a dozen juniors who can help on these issues NEST is growing fast.
I appreciate your hard work 馃挴 but it is just a turn-off for a developer if he/she has to spend hours on a simple problem.
Maybe this is a bug and needs a fix.

@Tochemey
Either your tsconfig.json is faulty, the import path or the filename ./json.result.js is incorrect. However, this is most likely not a Nest related problem so please as already mentioned use StackOverflow

@SamiHK

turn-off for a developer if he/she has to spend hours on a simple problem.

We fully understand that - we have all been there - but we can quite frankly not be a support desk for every question. These GitHub issues are here for collecting bugs / features / enhancements (and discussions to some degree) related to the code itself.

This issue is most likely not a problem with NestJS code - that is why we redirect it to StackOverflow or other channels because there are way more people who are happy to help there.

Maybe you can train a dozen juniors

Most open source projects do not work like that. Most contributors are volunteers who actually work for free <3. Nest does have super generous donators, but it is far from being sufficient to pay dozens of juniors.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thohoh picture thohoh  路  3Comments

JulianBiermann picture JulianBiermann  路  3Comments

VRspace4 picture VRspace4  路  3Comments

artaommahe picture artaommahe  路  3Comments

mishelashala picture mishelashala  路  3Comments