2024 Oct 09 1:13 PM - edited 2024 Oct 10 7:37 AM
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.
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
Request clarification before answering.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
70 | |
21 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.