SAP / ai-sdk-js

SAP Cloud SDK for AI is the official Software Development Kit (SDK) for SAP AI Core, SAP Generative AI Hub, and Orchestration Service.
Apache License 2.0
38 stars 5 forks source link

CAP NodeJS Project cannot use ai-sdk due to module handling #265

Closed ch-sap closed 3 weeks ago

ch-sap commented 4 weeks ago

Describe the Bug

Dear colleagues,

our Partner Reference Application is a CAP(NodeJS)/Fiori Elements project, which was created via CAP wizard. Per default, the CAP project was not created with type "module" in the package.json. Our CDS service implementation has therefore several require statements included to import files.

Unfortunately, the ai-sdk-js package does not support the "require" statement. It forces to use "import". At some places, like when using jest, we get the error "TypeError: A dynamic import callback was invoked without --experimental-vm-modules".

We would like to avoid changing our complete project to use this library, just to change the project to a module.

Could you please offer a solution for this? How shall a default CAP js application use your library?

Best regards, Christine

Steps to Reproduce

  1. Create a CAP project via wizard
  2. Add a service with an implementation that uses requires to add the library
  3. Error during build is thrown

Expected Behavior

The project should be usable with a default CAP js project.

Screenshots

No response

Used Versions

Code Examples

No response

Log File

No response

Affected Development Phase

Getting Started

Impact

Blocked

Timeline

No response

Additional Context

No response

tomfrenken commented 3 weeks ago

Hi @ch-sap,

the reason you are encountering this issue is that the SAP Cloud SDK for AI is an ESM project, which means you have to be an ESM project as well to use it. This means, changing require statements to import and changing the project type to module.

If you want the CAP wizard to natively support ESM, please approach the CAP team to update their wizard. If you want to see an example of a CAP-based project using our library, we do have a CAP sample application that you can use as a foundation to update your existing project.

ch-sap commented 3 weeks ago

Hi, thanks a lot for your respond. I created an issue for CAP. Newest version of CAP-LLM-PLUGIN can be used also with non-esm projects. Best regards, Christine

jjtang1985 commented 3 weeks ago

Hi @ch-sap,

Just want to make sure we are on the same page, you can use the SDK inside your CAP application, and you can check our CAP sample app, as mentioned by Tom.

ch-sap commented 3 weeks ago

Yes, but I do not have an ESM enabled CAP project and I do not want to change all imports now. So we first try the component, where we do not have to change our project an unstabilize our application.