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

nestjs Error when evaluating SSR module #8

Closed
productdevbook opened this issue Aug 26, 2021 · 14 comments
Closed

nestjs Error when evaluating SSR module #8

productdevbook opened this issue Aug 26, 2021 · 14 comments

Comments

@productdevbook
Copy link

12:32:41 PM [vite] Error when evaluating SSR module /src/app.module.ts:
Error: Failed to resolve import "src/guards/gql-auth.guard" from "src/auth/auth.module.ts". Does the file exist?
at formatError (/s/node_modules/vite/dist/node/chunks/dep-972722fa.js:51153:46)
at TransformContext.error (/s/node_modules/vite/dist/node/chunks/dep-972722fa.js:51149:19)
at normalizeUrl (/s/node_modules/vite/dist/node/chunks/dep-972722fa.js:74554:26)
at async TransformContext.transform (/s/node_modules/vite/dist/node/chunks/dep-972722fa.js:74687:57)
at async Object.transform (/s/node_modules/vite/dist/node/chunks/dep-972722fa.js:51354:30)
at async transformRequest (/s/node_modules/vite/dist/node/chunks/dep-972722fa.js:67098:29)
at async instantiateModule (/s/node_modules/vite/dist/node/chunks/dep-972722fa.js:73732:10)

@axe-me
Copy link
Owner

axe-me commented Aug 26, 2021

looks like something is wrong with the path. can you provide a minimum repro?

@productdevbook
Copy link
Author

I can ship in 2-3 weeks. I don't know how to break this into little pieces.

@productdevbook
Copy link
Author

productdevbook commented Sep 2, 2021

import { GqlAuthGuard } from 'src/guards/gql-auth.guard'; ->
import { GqlAuthGuard } from '../../guards/gql-auth.guard';
change and fixed. ✅

@productdevbook
Copy link
Author

new problem

5:15:49 PM [vite] Error when evaluating SSR module /src/app.module.ts:
ReferenceError: require is not defined
    at /src/app.module.ts:40:11
    at async instantiateModule (/s/node_modules/vite/dist/node/chunks/dep-1be34a63.js:75018:9)
5:15:49 PM [vite] Error when evaluating SSR module ./src/main.ts:
ReferenceError: require is not defined
    at /src/app.module.ts:40:11
    at async instantiateModule (/s/node_modules/vite/dist/node/chunks/dep-1be34a63.js:75018:9)
(node:30397) UnhandledPromiseRejectionWarning: ReferenceError: require is not defined
    at /src/app.module.ts:40:11
  

@unlight
Copy link

unlight commented Sep 3, 2021

#11 Looks like related

@axe-me
Copy link
Owner

axe-me commented Sep 6, 2021

do you have any requires in your app.module.ts ?
vite not support commonjs style requires, try use import

@productdevbook
Copy link
Author

do you have any requires in your app.module.ts ?
vite not support commonjs style requires, try use import

yes fixed. new problem

ReferenceError:: __dirname is not defined
at typeormModuleOptions (/src/config/database.config.ts:17:40)
at InstanceWrapper.eval [as metatype] (/src/config/database.config.ts:30:17)


 import { registerAs } from '@nestjs/config';
import { join } from 'path';
import { ConnectionOptions } from 'typeorm';
function typeormModuleOptions(): ConnectionOptions {
return {
 type: 'postgres',
 host: process.env.GENERAL_DATABASE_HOST,
 port: parseInt(process.env.GENERAL_DATABASE_PORT),
 username: process.env.GENERAL_DATABASE_USERNAME,
 password: process.env.GENERAL_DATABASE_PASSWORD,
 database: process.env.GENERAL_DATABASE_NAME,
 synchronize: Boolean(process.env.TYPEORM_SYNC),
 entities: [join(__dirname, '../**/**/*entity{.ts,.js}')],
 migrationsRun: true,
 migrations: [join(__dirname, '../migration/**/*{.ts,.js}')],
 migrationsTableName: 'migration_typeorm',

@productdevbook
Copy link
Author

productdevbook commented Sep 6, 2021

 entities: [join(__dirname, '../**/**/*entity{.ts,.js}')],
 migrationsRun: true,
 migrations: [join(__dirname, '../migration/**/*{.ts,.js}')],

and delete new problem.

[Nest] 60798  - 09/06/2021, 9:09:33 PM   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
Error: connect ECONNREFUSED 127.0.0.1:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1148:16)

@productdevbook
Copy link
Author

import { ConfigFactory, registerAs } from '@nestjs/config';
import { ConnectionOptions } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import * as path from 'path';


export const typeormModuleOptions: ConfigFactory<ConnectionOptions> = (
  configService?: ConfigService,
) => {

  const entitiesPath = path.resolve(__dirname, '../**/entities/*{.ts,.js}');
  const migrationPath = path.resolve(__dirname, '../../migration/*{.ts,.js}');
  const commonConfigs = {
    entities: [entitiesPath],
    migrations: [migrationPath],
    cli: {
      migrationsDir: 'migration',
    },
  };
  if (configService) {
    return {
      type: 'postgres',
      host: configService.get('GENERAL_DATABASE_HOST'),
      port: configService.get<number>('GENERAL_DATABASE_PORT'),
      username: configService.get('GENERAL_DATABASE_USERNAME'),
      password: configService.get('GENERAL_DATABASE_PASSWORD'),
      database: configService.get('GENERAL_DATABASE_NAME'),
      synchronize: configService.get<boolean>('TYPEORM_SYNC'),
      ...commonConfigs,
    };
  }

  return {
    type: 'postgres',
    host: process.env.GENERAL_DATABASE_HOST,
    port: parseInt(process.env.GENERAL_DATABASE_PORT),
    username: process.env.GENERAL_DATABASE_USERNAME,
    password: process.env.GENERAL_DATABASE_PASSWORD,
    database: process.env.GENERAL_DATABASE_NAME,
    synchronize: Boolean(process.env.TYPEORM_SYNC),
    ...commonConfigs,
  };
};

export default registerAs('database', typeormModuleOptions);

@productdevbook
Copy link
Author

[Nest] 70663 - 09/06/2021, 10:26:38 PM LOG [InstanceLoader] AwsSdkModule dependencies initialized +0ms
[Nest] 70663 - 09/06/2021, 10:26:38 PM LOG [InstanceLoader] GraphQLSchemaBuilderModule dependencies initialized +0ms
[Nest] 70663 - 09/06/2021, 10:26:38 PM LOG [InstanceLoader] RedisModule1 dependencies initialized +11ms
[Nest] 70663 - 09/06/2021, 10:26:38 PM LOG [InstanceLoader] GraphQLModule dependencies initialized +0ms
[Nest] 70663 - 09/06/2021, 10:26:38 PM LOG [InstanceLoader] TypeOrmCoreModule dependencies initialized +581ms
[Nest] 70663 - 09/06/2021, 10:26:38 PM ERROR [ExceptionHandler] No metadata for "User1" was found.
EntityMetadataNotFoundError: No metadata for "User1" was found.

dont used User1, i am used User -> why new name change add

@axe-me
Copy link
Owner

axe-me commented Sep 7, 2021

please see #9 (comment) for the __dirname issue

@productdevbook
Copy link
Author

productdevbook commented Sep 7, 2021

please see #9 (comment) for the __dirname issue

dir delete and new problem up

#8 (comment)

@axe-me
Copy link
Owner

axe-me commented Sep 7, 2021

I'm afraid I need you to provide a repro for this User model issue.

@axe-me
Copy link
Owner

axe-me commented May 11, 2022

close for now due to inactive.

@axe-me axe-me closed this as completed May 11, 2022
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

3 participants