question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Server.init fails when using Postgres and nest ConfigModule

See original GitHub issue

Describe the bug When using PostgresInitializer and ConfigModule in a plugin, the server.init fails and we get the following error : ‘Cannot destructure property ‘superadminCredentials’ of ‘configService.authOptions’ as it is undefined.’

To Reproduce

  • on a fresh Vendure install create a plugin :
import { Inject } from '@nestjs/common'
import { PluginCommonModule, VendurePlugin, ConfigService } from '@vendure/core'

import { applicationConfig } from './application.config'
import { ConfigModule, ConfigType } from '@nestjs/config'

@VendurePlugin({
  imports: [PluginCommonModule, ConfigModule.forFeature(applicationConfig)],
})
export class TestPlugin {
  readonly logPrefix = '[Job cleanup]'

  constructor(
    @Inject(applicationConfig.KEY)
    private appConfig: ConfigType<typeof applicationConfig>,
    private configService: ConfigService
  ) {}
}

Create the application.config :

import { registerAs } from '@nestjs/config'

export const applicationConfig = registerAs('app', () => ({
  executionContext: process.env.CONTEXT || 'SERVER',
  nodeEnv: process.env.NODE_ENV,
}))

Then create a 2e2 test :

import {
  createTestEnvironment,
  registerInitializer,
  SqljsInitializer,
  PostgresInitializer,
} from '@vendure/testing'
import path from 'path'
import { testConfig } from './config/test-config'
import { initialData } from './config/initial-data'
import { TestPlugin } from '../../../src/plugins/test/test-plugin'

const sqliteDataDir = path.join(__dirname, '__data__');
//registerInitializer('sqljs', new SqljsInitializer(sqliteDataDir));
registerInitializer('postgres', new PostgresInitializer())


describe('products plugin', () => {
  const { server } = createTestEnvironment({
    ...testConfig,
    plugins: [TestPlugin],
  })

  // The timeout needs to be a little long to be able to init the database
  beforeAll(async () => {
    await server.init({
      initialData,
      productsCsvPath: path.join(__dirname, 'config/test-products.csv'),
      customerCount: 1,
    })
  }, 120000)

  afterAll(async () => {
    await server.destroy()
  })

  it('Test', async () => {
    expect(true).toEqual(true)
  })
})

Then run the test with Jest

Expected behavior Server.init should work

Environment (please complete the following information):

  • Dependencies :
    "@nestjs/config": "^1.1.6",
    "@types/jest": "^26.0.20",
    "@vendure/admin-ui-plugin": "1.4.4",
    "@vendure/asset-server-plugin": "1.4.4",
    "@vendure/core": "1.4.4",
    "@vendure/email-plugin": "1.4.4",
    "@vendure/testing": "1.4.3",
    "@vendure/ui-devkit": "1.4.3",
    "jest": "^26.6.3",
    "jest-junit": "^13.0.0",
    "pg": "^8.7.1",
    "sql.js": "1.6.2",
    "ts-jest": "^26.4.4",
    "typescript": "4.3.5"
  • Database : postgres

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ttourniecommented, Jan 14, 2022

Ok so the TypeError: Cannot read property 'value' of undefined was an issue in our end, we declared the ChannelService has a provider in one of our plugin for no reason

0reactions
michaelbromleycommented, Jan 14, 2022

OK, I will close this now then. The underlying issue for the ConfigModule will be automatically resolved when we upgrade NestJS in v2.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't init TypeOrmModule using factory and forRootAsync
I get a tremendous error when I run a build.... but the app still runs. $ rimraf dist && tsc src/database/database.module.ts:14:7 - error...
Read more >
NestJS setup TypeOrm connection with .env and @nestjs/config
It's my working script with Postgres in app.module.ts, ... you are trying to inject a class using dependency injection, however Nest can't ...
Read more >
Configuration | NestJS - A progressive Node.js framework
A good approach for using this technique in Nest is to create a ConfigModule that exposes a ConfigService which loads the appropriate .env...
Read more >
Setting up Nestjs with PostgreSQL - Dev Genius
I recently started working with NestJs and I would like to share how you can connect a simple server-side application with a running...
Read more >
API with NestJS #2. Setting up a PostgreSQL database with ...
I see you have create services for “postgres”, “pgadmin”, that's really good. But I don't see that you create a service for “Nest...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found