Skip to content

Commit f4ad53f

Browse files
authored
Do not treat bunders as node.js
When using this library under [Parcel](https://parceljs.org/), `isNode` is true even inside the browser. This is probably true for Webpack and other bundlers as well, since they all emulate the `module` system. This version checks for `process.versions.node`, which is defined on ever version of Node.js since 0.2.0.
1 parent 0095f0b commit f4ad53f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
44

5-
const isNode = typeof module !== 'undefined' && typeof module.exports !== 'undefined';
5+
const isNode =
6+
typeof process !== 'undefined' &&
7+
process.versions != null &&
8+
process.versions.node != null;
69

710
export {
811
isBrowser,

0 commit comments

Comments
 (0)