cancel
Showing results for 
Search instead for 
Did you mean: 

ERROR: Upgrading @cap/cds and @cap/cds-dk to version 8

BastiMankel
Explorer
1,271

In my CAP backend project I use nestjs. In version 7.9.3 of the @sap/cds and @sap/cds-dk packages, everything worked as expected. After updating these packages to version 8, an error occurs when I call my cds service: “ ERROR TypeError: Cannot read properties of undefined (reading ‘definitions’)”. The error occurs both in the $metadata and during a read operation on an entity.

BastiMankel_0-1728476394953.png

The code snippet where I serve the OData service using @sap/cds framework: 

 

  async configure(_consumer: MiddlewareConsumer) {
    await cds
      .serve('SampleService')
      .in(this.adapterHost.httpAdapter)
      .from("cds")
      .at('/odata')
      .with(this.handler.serviceHandler);
  }

 

You can find my project on GitHub: https://github.com/BastiInnovation/cap-template

View Entire Topic
detrapto
Explorer
0 Kudos

The solution provided via SAP Me:

When using a custom server file (what we do here), the cds.model has to be set manually. This can either be achieved via:

const csn = await cds.load('*')         // or 'cds' in our case
.then (cds.minify)
cds.model = cds.compile.for.nodejs (csn)

or by precompiling the model at build time via an npm script and loading its resulting JSON into cds.model at application startup:

// package.json > scripts
"prebuild": "cds compile cds -4 nodejs -o src/model.json"

// App initialization:
cds.model = require ('./model.json');

The former solution can also meanwhile be found within the CAPire documentation at https://cap.cloud.sap/docs/node.js/cds-server#built-in-server-js .

Since @cap-js/cds-types did not support `cds.compile.for.nodejs` and `cds.minify` at the time of issue creation, but in the meantime the respective issue (https://github.com/cap-js/cds-types/issues/292) has been closed and should be available pretty soon.