Server.init fails when using Postgres and nest ConfigModule
See original GitHub issueDescribe 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:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 reasonOK, I will close this now then. The underlying issue for the ConfigModule will be automatically resolved when we upgrade NestJS in v2.0