@ha-bits/cortex 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,6 +39,26 @@ npx @ha-bits/cortex server --config ./config.json
39
39
 
40
40
  The CLI requires a configuration file. See the documentation for configuration options.
41
41
 
42
+ ## Technical Notes
43
+
44
+ ### Dynamic Module Loading
45
+
46
+ Cortex uses `createRequire` from Node.js's `module` API instead of the standard `require()` for loading modules at runtime. This is necessary because:
47
+
48
+ 1. **Bundler Compatibility**: When the code is bundled with esbuild/webpack then ncc, the bundler transforms `require()` calls and creates a static context that can't resolve paths determined at runtime.
49
+
50
+ 2. **Dynamic Path Resolution**: Activepieces modules are downloaded to `/tmp/habits-nodes/` or wherever the env points to at runtime and their paths aren't known at build time. Using `createRequire(__filename)` creates a fresh require function that bypasses the bundler's static analysis.
51
+
52
+ 3. **Production Environment**: In production (`/app/dist/pack/index.cjs`), the bundled code would throw "Cannot find module" errors with regular `require()` because webpack's `webpackEmptyContext` can't resolve dynamic paths.
53
+
54
+ ```typescript
55
+ // Instead of: require(dynamicPath) // ❌ Fails in bundled code
56
+ // We use:
57
+ import { createRequire } from 'module';
58
+ const dynamicRequire = createRequire(__filename);
59
+ const loadedModule = dynamicRequire(dynamicPath); // ✅ Works in bundled code
60
+ ```
61
+
42
62
  ## License
43
63
 
44
64
  Apache-2.0