Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit d8df0d4

Browse files
committed
temporary fixed the import issue
1 parent 283a4ac commit d8df0d4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/core/src/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ export function optionalRequire<PackageType = any>(
215215
try {
216216
requiredPackage = require(moduleName);
217217
} catch (e) {
218-
if (error) LogCodeManager.log('20:03:02', [moduleName]);
218+
if (error) {
219+
LogCodeManager.log('20:03:02', [moduleName]);
220+
console.log(e);
221+
}
219222
}
220223
return requiredPackage;
221224
}

packages/react/src/hooks/useAgile.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@ import {
1414
extractRelevantObservers,
1515
SelectorWeakMapType,
1616
SelectorMethodType,
17-
optionalRequire,
1817
} from '@agile-ts/core';
1918
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
2019
import { normalizeArray } from '@agile-ts/utils';
2120
import { AgileOutputHookArrayType, AgileOutputHookType } from './useOutput';
22-
const proxyPackage = optionalRequire('@agile-ts/proxytree');
21+
22+
// TODO https://stackoverflow.com/questions/68148235/require-module-inside-a-function-doesnt-work
23+
let proxyPackage: any = null;
24+
try {
25+
proxyPackage = require('@agile-ts/proxytree');
26+
} catch (e) {
27+
// empty catch block
28+
}
2329

2430
/**
2531
* A React Hook for binding the most relevant value of multiple Agile Instances
@@ -88,7 +94,8 @@ export function useAgile<
8894
// Wrap a Proxy around the object to track the accessed properties.
8995
if (config.proxyBased && isValidObject(value, true)) {
9096
if (proxyPackage != null) {
91-
const proxyTree = new proxyPackage.ProxyTree(value);
97+
const { ProxyTree } = proxyPackage;
98+
const proxyTree = new ProxyTree(value);
9299
proxyTreeWeakMap.set(dep, proxyTree);
93100
return proxyTree.proxy;
94101
} else {

0 commit comments

Comments
 (0)