소스 검색

fix(create): add useDefineForClassFields to fix ES2022 (#4116)

Co-authored-by: Housein Abo Shaar <76689341+GogoIsProgramming@users.noreply.github.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Housein Abo Shaar 11 시간 전
부모
커밋
fe25af0920
2개의 변경된 파일19개의 추가작업 그리고 0개의 파일을 삭제
  1. 18 0
      docs/docs/guides/developer-guide/database-entity/index.md
  2. 1 0
      packages/create/templates/tsconfig.template.json

+ 18 - 0
docs/docs/guides/developer-guide/database-entity/index.md

@@ -39,6 +39,24 @@ class ProductReview extends VendureEntity {
 }
 ```
 
+:::caution TypeScript ES2022+ Compatibility
+If your `tsconfig.json` uses `"target": "ES2022"` or later (including **Node.js v24+**), you **must** also set `"useDefineForClassFields": false`.
+
+Without this setting, ES2022 class field semantics cause entity fields to be overwritten with `undefined` after the constructor runs, resulting in "null value in column violates not-null constraint" database errors.
+
+```json title="tsconfig.json"
+{
+    "compilerOptions": {
+        "target": "ES2022",
+        // highlight-next-line
+        "useDefineForClassFields": false
+    }
+}
+```
+
+See the [TypeScript documentation](https://www.typescriptlang.org/tsconfig/useDefineForClassFields.html) for more details.
+:::
+
 :::note
 Any custom entities *must* extend the [`VendureEntity`](/reference/typescript-api/entities/vendure-entity/) class.
 :::

+ 1 - 0
packages/create/templates/tsconfig.template.json

@@ -6,6 +6,7 @@
     "esModuleInterop": true,
     "emitDecoratorMetadata": true,
     "experimentalDecorators": true,
+    "useDefineForClassFields": false,
     "strictPropertyInitialization": false,
     "target": "es2019",
     "strict": true,