Skip to content

Commit 7b02583

Browse files
committed
throw if firebaseServerApp constructed in browser. Remove lib ESNext from app tsconfig
1 parent 8a745d1 commit 7b02583

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

packages/app/src/api.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import {
4848
LogOptions,
4949
setUserLogHandler
5050
} from '@firebase/logger';
51-
import { deepEqual, getDefaultAppConfig } from '@firebase/util';
51+
import { deepEqual, getDefaultAppConfig, isBrowser } from '@firebase/util';
5252

5353
export { FirebaseError } from '@firebase/util';
5454

@@ -229,6 +229,11 @@ export function initializeServerApp(
229229
_options: FirebaseOptions | FirebaseApp,
230230
_serverAppConfig: FirebaseServerAppSettings
231231
): FirebaseServerApp {
232+
if (isBrowser()) {
233+
// FirebaseServerApps aren't designed to be run in browsers.
234+
throw ERROR_FACTORY.create(AppError.INVALID_SERVER_APP_ENVIRONMENT);
235+
}
236+
232237
const serverAppSettings: FirebaseServerAppSettings = {
233238
automaticDataCollectionEnabled: false,
234239
..._serverAppConfig

packages/app/src/errors.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export const enum AppError {
3030
IDB_GET = 'idb-get',
3131
IDB_WRITE = 'idb-set',
3232
IDB_DELETE = 'idb-delete',
33-
FINALIZATION_REGISTRY_NOT_SUPPORTED = 'finalization-registry-not-supported'
33+
FINALIZATION_REGISTRY_NOT_SUPPORTED = 'finalization-registry-not-supported',
34+
INVALID_SERVER_APP_ENVIRONMENT = 'invalid-server-app-environment'
3435
}
3536

3637
const ERRORS: ErrorMap<AppError> = {
@@ -58,7 +59,9 @@ const ERRORS: ErrorMap<AppError> = {
5859
[AppError.IDB_DELETE]:
5960
'Error thrown when deleting from IndexedDB. Original error: {$originalErrorMessage}.',
6061
[AppError.FINALIZATION_REGISTRY_NOT_SUPPORTED]:
61-
"FirebaseServerApp '{$appName}' deleteOnDeref field defined but the JS runtime does not support FinalizationRegistry."
62+
'FirebaseServerApp deleteOnDeref field defined but the JS runtime does not support FinalizationRegistry.',
63+
[AppError.INVALID_SERVER_APP_ENVIRONMENT]:
64+
'FirebaseServerApp is not for use in browser environments.'
6265
};
6366

6467
interface ErrorParams {

packages/app/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"extends": "../../config/tsconfig.base.json",
33
"compilerOptions": {
44
"outDir": "dist",
5-
"downlevelIteration": true,
6-
"lib": ["ESNext"],
5+
"downlevelIteration": true
76
},
87
"exclude": [
98
"dist/**/*"

0 commit comments

Comments
 (0)