Skip to content

Commit 67fb29b

Browse files
authored
fix: reduce global DOM/Node type conflicts in server-only packages (#12737)
Currently, we globally enable both DOM and Node.js types. While this mostly works, it can cause conflicts - particularly with `fetch`. For example, TypeScript may incorrectly allow browser-only properties (like `cache`) and reject valid Node.js ones like `dispatcher`. This PR disables DOM types for server-only packages like payload, ensuring Node-specific typings are applied. This caught a few instances of incorrect fetch usage that were previously masked by overlapping DOM types. This is not a perfect solution - packages that contain both server and client code (like richtext-lexical or next) will still suffer from this issue. However, it's an improvement in cases where we can cleanly separate server and client types, like for the `payload` package which is server-only. ## Use-case This change enables #12622 to explore using node-native fetch + `dispatcher`, instead of `node-fetch` + `agent`. Currently, it will incorrectly report that `dispatcher` is not a valid property for node-native fetch
1 parent 018317d commit 67fb29b

File tree

43 files changed

+205
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+205
-187
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
"@types/fs-extra": "^11.0.2",
142142
"@types/jest": "29.5.12",
143143
"@types/minimist": "1.2.5",
144-
"@types/node": "22.5.4",
144+
"@types/node": "22.15.30",
145145
"@types/react": "19.1.0",
146146
"@types/react-dom": "19.1.2",
147147
"@types/shelljs": "0.8.15",

packages/create-payload-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"@types/esprima": "^4.0.6",
7878
"@types/fs-extra": "^9.0.12",
7979
"@types/jest": "29.5.12",
80-
"@types/node": "22.5.4"
80+
"@types/node": "22.15.30"
8181
},
8282
"engines": {
8383
"node": "^18.20.2 || >=20.9.0"

packages/create-payload-app/src/lib/examples.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function getExamples({ branch }: { branch: string }): Promise<Proje
77

88
const response = await fetch(url)
99

10-
const examplesResponseList: { name: string; path: string }[] = await response.json()
10+
const examplesResponseList = (await response.json()) as { name: string; path: string }[]
1111

1212
const examples: ProjectExample[] = examplesResponseList.map((example) => ({
1313
name: example.name,

packages/create-payload-app/src/utils/getLatestPackageVersion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function getLatestPackageVersion({
1919
}) {
2020
try {
2121
const response = await fetch(`https://registry.npmjs.org/${packageName}`)
22-
const data = await response.json()
22+
const data = (await response.json()) as { 'dist-tags': { latest: string } }
2323
const latestVersion = data['dist-tags'].latest
2424

2525
if (debug) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
22
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
// Do not include DOM and DOM.Iterable as this is a server-only package.
5+
"lib": ["ES2022"],
6+
}
37
}

packages/db-mongodb/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
22
"extends": "../../tsconfig.base.json",
3-
"references": [{ "path": "../payload" }, { "path": "../translations" }]
3+
"references": [{ "path": "../payload" }, { "path": "../translations" }],
4+
"compilerOptions": {
5+
// Do not include DOM and DOM.Iterable as this is a server-only package.
6+
"lib": ["ES2022"],
7+
}
48
}

packages/db-postgres/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@
1010
{
1111
"path": "../drizzle"
1212
}
13-
]
13+
],
14+
"compilerOptions": {
15+
// Do not include DOM and DOM.Iterable as this is a server-only package.
16+
"lib": ["ES2022"],
17+
}
1418
}

packages/db-sqlite/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@
1010
{
1111
"path": "../drizzle"
1212
}
13-
]
13+
],
14+
"compilerOptions": {
15+
// Do not include DOM and DOM.Iterable as this is a server-only package.
16+
"lib": ["ES2022"],
17+
}
1418
}

packages/db-vercel-postgres/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@
1010
{
1111
"path": "../drizzle"
1212
}
13-
]
13+
],
14+
"compilerOptions": {
15+
// Do not include DOM and DOM.Iterable as this is a server-only package.
16+
"lib": ["ES2022"],
17+
}
1418
}

packages/drizzle/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
/* TODO: remove the following lines */
55
"strict": false,
66
"noUncheckedIndexedAccess": false,
7+
// Do not include DOM and DOM.Iterable as this is a server-only package.
8+
"lib": ["ES2022"],
79
},
810
"references": [{ "path": "../payload" }, { "path": "../translations" }]
911
}

0 commit comments

Comments
 (0)