gorules / zen

Open-source Business Rules Engine for your Rust, NodeJS, Python or Go applications.
https://gorules.io
MIT License
770 stars 74 forks source link

__dirname is not defined in ES module scope #182

Open vincent-musto opened 3 months ago

vincent-musto commented 3 months ago

I am trying to deploy Zen Engine in Typescript Node.js Lambda using ES Modules deployed via Typescript CDK utilizing ESBuild. I am able to deploy the lambda, but get "__dirname is not defined in ES module scope" error upon initialization. How do I address this?

Let me know if you need more details or context.

stefan-gorules commented 3 months ago

This might be related to: https://github.com/napi-rs/napi-rs/issues/1948. For now, would you be able to use webpack instead?

If you've managed to find a solution, would you be able to write it down so that we may document it somewhere. Thanks!

stefan-gorules commented 2 months ago

Hi @vincent-musto, have you figured out the solution?

vincent-musto commented 2 months ago

@stefan-gorules - I have not found a solution, but a workaround: I have added @gorules/zen-engine and @gorules/zen-engine-linux-x64-gnu to a Lambda Layer, which is attached to the Lambda where I am using the Zen Engine. This avoids the bundling process and allows me to make @gorules/zen-engine and @gorules/zen-engine-linux-x64-gnu External Modules. It has been working fine without much extra overhead, though it would be preferable to remove the Lambda Layer in the future.

bjorntheart commented 3 weeks ago

@vincent-musto this is how I got __dirname to work, but only on my local machine.

import path from "node:path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const dataRoot = path.join(__dirname, "internal/rater/rules");