TIL - How to force a specific version of SAP UI5 when running Fiori preview in a CAP project

Today I was running a very simple CAP service, which is part of the Service integration with SAP Cloud Application Programming model CodeJam. When running the Fiori preview for an entity, I was always getting an error message in the console: TypeError: o.intersection is not a function. This error was being raised by the Fiori preview independent of the entity that I was trying to preview. That made me thing that the issue was not with the entity but with the Fiori preview itself.

Fiori preview error
Fiori preview error

Based on the network requests that I was able to see in the Developer Tools, I knew it was using version 1.132.0 of SAP UI5. Then I thought… let’s force the project to use a different version to see if the error would go away. I debugged the CAP project and I knew exactly where was the version of SAP UI5 being set. I set the variable to 1.130.0 and the preview worked fine. Nice!

Debug forcing version
Debug forcing version

Now, I don’t want to debug the project every time and manually set the version…. digging deeper, I found out that the @sap/cds-fiori module has a package.json, where the version of SAP UI5 is set. It is well known that you can set project-specific configuration via a .env file. So, I created a .env file in the root of the project and set the following content:

cds.fiori.preview.ui5.version=1.130.0

By setting that environment variable I’m forcing the project to use version 1.130.0 of SAP UI5 when running the Fiori preview. I restarted the project and the preview worked fine.

Fiori preview running specific version
Fiori preview running specific version

Written on March 18, 2025