MemberJunction / MemberJunction/MJ

Bug Report: Issue during MJ installation during the codegen phase due to key casing

Open
#2,793 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TSQL
Stars
29
Forks
6
Avg merge
2d 1h
Merged PRs (30d)
323

Description

**Describe the bug**
CodeGen fails with `"config.server" property is required` due to `newUserSetup` key casing. This blocks the 'mj install' at the 'codegen' phase.

**Component:** MemberJunction CLI / `@memberjunction/codegen-lib` config loader
**Affected version:** `@memberjunction/cli` 5.39.0 (`mjRepoVersion: v5.39.0`)
**Status:** Worked around locally (config edit). Root cause is an upstream installer + config-validation issue.

The error message given when installation fails is misleading:
* Starting MemberJunction CodeGen (undefined) @ ...
* Initializing database connection... ✖ CodeGen failed: TypeError: The "config.server" property is required and must be of type string.

As well as some TypeScript error logs:
```
mj_generatedentities:build: src/index.ts(1,15): error TS2307:
Cannot find module './generated/entity_subclasses.js' or its corresponding type declarations.
mj_generatedactions:build: src/index.ts(1,15): error TS2307:
Cannot find module './generated/action_subclasses.js' ...
```

But the core issue stems from the fact that the config itself failed to load. Debugged revealed that the config object was '(undefined)'.

## Root cause

CodeGen merges built-in defaults + `.env` + `mj.config.cjs`, then validates the merged object
against a strict zod schema. On validation failure it does **not** throw a useful error and it
silently falls back to an empty object:

```js
// node_modules/@memberjunction/codegen-lib/dist/Config/config.js
const configParsing = configInfoSchema.safeParse(mergedConfig);
export const configInfo = configParsing.data ?? {}; // <-- {} on any validation failure
```

What broke validation is the newUserSetup block in the mj.config.cjs file is using snakeCase, but the schema requires PascalCase.

```js
// Schema (config.js)
const newUserSetupSchema = z.object({
UserName: z.string(),
FirstName: z.string(),
LastName: z.string(),
Email: z.string(),
});
```

```js
// What the installer generated in mj.config.cjs
newUserSetup: {
userName: '',
firstName: '',
lastName: '',
email: '',
},
```

Claude deduced that because validation fails, then the entire config fails, and the config falls back to an empty object, which then propagates more errors upstream.

Fix / workaround
Rename the keys in mj.config.cjs to PascalCase:

```js
newUserSetup: {
UserName: '',
FirstName: '',
LastName: '',
Email: '',
},
```
following by resuming installation at a previous checkpoint.

**To Reproduce**
Steps to reproduce the behavior:
1. Run a fresh MemberJunction install on a new directory: mj install with @memberjunction/cli 5.39.0 (mjRepoVersion: v5.39.0, the latest version on the cli) on Node 24 in my case.
In the generated mj.config.cjs, ensure the newUserSetup block uses lowercase keys (this is what the installer writes):

```js
newUserSetup: {
userName: '',
firstName: '',
lastName: '',
email: '',
},
```

Make sure .env has valid DB settings (DB_HOST, DB_DATABASE, CODEGEN_DB_USERNAME, etc.) and confirm the failure is not actually about the database.

How to diagnose (if you hit a similar silent config failure)
The loader swallows the validation error. To see the real reason, temporarily log the zod issues
right after the safeParse call in
node_modules/@memberjunction/codegen-lib/dist/Config/config.js:

```js
const configParsing = configInfoSchema.safeParse(mergedConfig);
if (!configParsing.success) {
console.error('ZOD_ISSUES', JSON.stringify(configParsing.error.issues, null, 2));
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.