Skip to content

Commit 026748d

Browse files
authored
Running a Node.js environment check at installation (#434)
* Running a Node.js environment check at installation * Made the env check a run-time check * Updated changelog * Checking for the process variable instead of global (global is not present in browsers)
1 parent 0fdc901 commit 026748d

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22

3-
-
3+
- [fixed] Implemented a Node.js environment check that will be executed at
4+
package import time.
45

56
# v6.5.0
67

src/index.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,22 @@
1616

1717
import * as firebase from './default-namespace';
1818

19-
// Register the Database service
20-
// For historical reasons, the database code is included as minified code and registers itself
21-
// as a side effect of requiring the file.
22-
/* tslint:disable:no-var-requires */
23-
// require('./database/database');
24-
/* tslint:enable:no-var-requires */
19+
// Only Node.js has a process variable that is of [[Class]] process
20+
const processGlobal = typeof process !== 'undefined' ? process : 0;
21+
if (Object.prototype.toString.call(processGlobal) !== '[object process]') {
22+
const message = `
23+
======== WARNING! ========
24+
25+
firebase-admin appears to have been installed in an unsupported environment.
26+
This package should only be used in server-side or backend Node.js environments,
27+
and should not be used in web browsers or other client-side environments.
28+
29+
Use the Firebase JS SDK for client-side Firebase integrations:
30+
31+
https://firebase.google.com/docs/web/setup
32+
`;
33+
// tslint:disable-next-line:no-console
34+
console.error(message);
35+
}
2536

2637
export = firebase;

0 commit comments

Comments
 (0)