Skip to content

Commit

Permalink
fix(shared): process.env is undefined on non-node runtime issue (#93)
Browse files Browse the repository at this point in the history
* fix: process.env.JEST_WORKER_ID is undefined issue

Add null check to `process.env.JEST_WORKER_ID`, and access `process`
from `globalThis` to support non-node runtime.

* Update findPackageJSON.ts

---------

Co-authored-by: Oleksandr Fediashov <[email protected]>
  • Loading branch information
AsukaCHikaru and layershifter authored Jul 18, 2024
1 parent 3cadae5 commit c67ca85
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions packages/shared/src/findPackageJSON.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { dirname, isAbsolute } from 'path';
import * as process from 'process';

import findUp from 'find-up';

const cache = new Map<string, string | undefined>();
Expand All @@ -10,7 +8,7 @@ export function findPackageJSON(
filename: string | null | undefined
) {
// Jest's resolver does not work properly with `moduleNameMapper` when `paths` are defined
const isJest = Boolean(process.env.JEST_WORKER_ID);
const isJest = Boolean(globalThis.process?.env?.JEST_WORKER_ID);
const skipPathsOptions = isJest && !pkgName.startsWith('.');

try {
Expand Down

0 comments on commit c67ca85

Please sign in to comment.