`Uncaught ReferenceError: sap is not defined` after self-contained build with UI5 Tooling

445 views Asked by At

I have already built an application using SAPUI5 1.108. When launch the application locally (npm run start), everything works as expected.
However, I didn't notice that the system where the application is to be deployed into does not have the SAPUI5 version 1.108 but the version 1.71. Since the latter one lacks some features that the former has, the application won't run.
Therefore, I wanted to create a self-contained build of the application and deploy a project built this way. Unfortunately, after building the application this way, when I run the index.html file, the application doesn't even work locally.

When I try to build a self-contained application, none of the following give a working result:
ui5 build self-contained --include-all-dependencies --clean-dest --dest dist
ui5 build self-contained --include-all-dependencies --config=ui5.yaml --clean-dest --dest dist

The error I'm getting in the browser console:
Uncaught ReferenceError: sap is not defined at sap-ui-custom.js:1:1

I've noticed that the resources directory in the built application does not contain the sap-ui-core.js file, but I assume that this itself is not a problem as the path in the index.html is updated to the sap-ui-custom.js file.

The file explorer in Visual Studio Code showing the contents of the dist/resources directory

The @ui5/cli version I am using is 3.7.0.

1

There are 1 answers

0
RandomByte On BEST ANSWER

Make sure all relevant framework dependencies are available during the build (especially sap.ui.core). They should be declared in the ui5.yaml. You can check what dependencies UI5 Tooling will use by executing ui5 ls --flat.

If this does not help you in finding the issue, I'd propose to raise a bug report at https://github.com/SAP/ui5-tooling/issues/new/choose

If possible, provide your whole project. If not, provide at least the full build log (add the --verbose flag), the content of your ui5.yaml, the index.html from the build result and the first couple of lines of the generated sap-ui-custom.js.