Skip to content

Commit 7aee4aa

Browse files
authored
fix: detect process before use (#172)
Access process as a property of `globalThis` instead of as a global as parcel has stopped bundling the polyfill. Fixes: ``` ipfs: @parcel/core: Failed to resolve 'process' from ipfs: './node_modules/ipfs-utils/src/env.js' ipfs: /tmp/test-dependant-1646117523100/node_modules/ipfs-utils/src/env.js:10:57 ipfs: 9 | const IS_ELECTRON_RENDERER = IS_ELECTRON && IS_ENV_WITH_DOM ipfs: > 10 | peof process !== 'undefined' && typeof process.release !== 'undefined' ipfs: > | ^^^^^^^ ipfs: 11 | // @ts-ignore - we either ignore worker scope or dom scope ipfs: 12 | const IS_WEBWORKER = typeof importScripts === 'function' && typeof self ipfs: @parcel/resolver-default: Node builtin polyfill "process" is not installed, but ipfs: auto install is disabled. ```
1 parent 96ebe21 commit 7aee4aa

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/env.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const IS_ELECTRON = isElectron()
77
const IS_BROWSER = IS_ENV_WITH_DOM && !IS_ELECTRON
88
const IS_ELECTRON_MAIN = IS_ELECTRON && !IS_ENV_WITH_DOM
99
const IS_ELECTRON_RENDERER = IS_ELECTRON && IS_ENV_WITH_DOM
10-
const IS_NODE = typeof require === 'function' && typeof process !== 'undefined' && typeof process.release !== 'undefined' && process.release.name === 'node' && !IS_ELECTRON
10+
const IS_NODE = typeof require === 'function' && typeof globalThis.process !== 'undefined' && typeof globalThis.process.release !== 'undefined' && globalThis.process.release.name === 'node' && !IS_ELECTRON
1111
// @ts-ignore - we either ignore worker scope or dom scope
1212
const IS_WEBWORKER = typeof importScripts === 'function' && typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope
13-
const IS_TEST = typeof process !== 'undefined' && typeof process.env !== 'undefined' && process.env.NODE_ENV === 'test'
13+
const IS_TEST = typeof globalThis.process !== 'undefined' && typeof globalThis.process.env !== 'undefined' && globalThis.process.env.NODE_ENV === 'test'
1414
const IS_REACT_NATIVE = typeof navigator !== 'undefined' && navigator.product === 'ReactNative'
1515

1616
module.exports = {

0 commit comments

Comments
 (0)