Closed Sygyzmundovych closed 4 years ago
And while cf push -f gen/db
finished Ok, I see that tables SAP_COMMON_CURRENCIES
and SAP_COMMON_CURRENCIES_TEXTS
in my HDI schema are empty. I assume they should be populated from common/data
?
Indeed, there is no folder common under the gen, while the gen/srv/package.json has it as a dependency:
The models from ../common
are already compiled into the effective model file in gen/srv/csn.json
, so this dependency is actually not needed on CF. However, as the node.js buildpack always does an npm install
, this fails. Not sure here about the proper solution...
Hi @chgeo , is there any update on this? I have been getting the exact same error as @Sygyzmundovych
I was able to get past the initial error by removing the ../common dependency (and adding @sap/hana-client to the /bookshop app.), but then when I try to /browse Books, I get:
2020-04-28T20:44:12.99-0700 [APP/PROC/WEB/0] OUT > READ Books { '$count': 'true', '$skip': '0', '$top': '30' }
2020-04-28T20:44:13.09-0700 [APP/PROC/WEB/0] ERR [2020-04-29T03:44:13.089Z | ERROR | 1503087]: Cannot read property 'schema' of undefined
2020-04-28T20:44:13.09-0700 [APP/PROC/WEB/0] ERR [INTERNAL ERROR] TypeError: Cannot read property 'schema' of undefined
2020-04-28T20:44:13.09-0700 [APP/PROC/WEB/0] ERR at Promise (/home/vcap/deps/0/node_modules/@sap/cds-hana/lib/client/Client.js:93:31)
2020-04-28T20:44:13.09-0700 [APP/PROC/WEB/0] ERR at new Promise (cds run
2020-04-28T20:44:13.28-0700 [APP/PROC/WEB/0] ERR npm ERR! Exit status 1
2020-04-28T20:44:13.28-0700 [APP/PROC/WEB/0] ERR npm ERR!
2020-04-28T20:44:13.28-0700 [APP/PROC/WEB/0] ERR npm ERR! Failed at the @capire/bookshop@1.0.0 start script.
2020-04-28T20:44:13.28-0700 [APP/PROC/WEB/0] ERR npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-04-28T20:44:13.29-0700 [APP/PROC/WEB/0] ERR npm ERR! A complete log of this run can be found in:
2020-04-28T20:44:13.29-0700 [APP/PROC/WEB/0] ERR npm ERR! /home/vcap/app/.npm/_logs/2020-04-29T03_44_13_288Z-debug.log
2020-04-28T20:44:13.41-0700 [APP/PROC/WEB/0] OUT Exit status 1
was able to get past the initial error by removing the ../common dependency
Yes, that's a workaround for the missing dependency
and adding @sap/hana-client to the /bookshop app
Good!
Cannot read property 'schema' of undefined
You can check the application log where it says connect to...
to which DB it wants to connect. You maybe read undefined
there, which indicates a configuration error.
I remember the current version has a bug where the kind:sql
in the package.json is not properly resolved to hana
on Cloud Foundry, which would explain the issue. A fixed version of @sap/cds
will be published today, so you might wait a bit, or replace the sql
with hana
in package.json, and then build and deploy again.
The new version 3.34.1 of @sap/cds
is published. Please use this one with the sql
configuration.
Thanks for your help so far @chgeo - I'm no longer seeing the "Cannot read property 'schema' of undefined" error when trying to read from /browse/Books. However, I am seeing a consistent problem with reading entities from the CDS API in nodejs: that is, in all exported service implementations, cds.entities and/or db.entities (after connecting to database) show as undefined at runtime. I'm seeing this in capsamples as well.
For testing, I added the following log step to bookshop/gen/srv/srv/cat-service.js then deployed to cf. (service is created by 'cf cs hana hdi-shared bookshop-db-hdi-container')
const cds = require('@sap/cds')
module.exports = async function (){
const db = await cds.connect.to('db') // connect to database service
const { Books } = db.entities // get reflected definitions
// vvvvvvvv below line added
console.log(`[cat-service] Fetched Books entity ${JSON.stringify(Books)}`)
...
Now, cds.entities works fine in a local run (cds watch) and I can effectively create new books and orders, but I see in the logs (cf logs bookshop-srv --recent) the following
... 2020-04-29T07:49:56.26-0700 [APP/PROC/WEB/0] OUT [cds] - serving AdminService { at: '/admin' } 2020-04-29T07:49:58.56-0700 [APP/PROC/WEB/0] OUT [cds] - serving CatalogService { at: '/browse', impl: 'srv/cat-service.js' } 2020-04-29T07:49:58.56-0700 [APP/PROC/WEB/0] OUT [cat-service] Fetched Books entity undefined 2020-04-29T07:49:58.66-0700 [APP/PROC/WEB/0] OUT [cds] - launched in: 18695.134ms 2020-04-29T07:49:58.66-0700 [APP/PROC/WEB/0] OUT [cds] - server listening on { url: 'http://localhost:8080' } ...
Also, is there documentation for how to deploy the fiori/app contents to cloud-foundry? Should we use html5-app-deployer?
After a bit of digging I found the service implementations (cat-service.js, admin-service.js and orders-service.js) work when deployed to CF if the API call to cds.entities explicitly includes the namespace.
i.e.,
const db = await cds.connect.to('db') // connect to database service
const { Books } = db.entities('sap.capire.bookshop') // get reflected definitions
or
const { Books } = cds.entities('sap.capire.bookshop')
Is this the correct approach?
Both are equivalent (assumed in the second case primary db has been connected, which usually happens on bootstrapping). cds
acts as a shortcut to connected primary db, which is accessible thru cds.db
and will be exactly the cached service object you get from subsequent invocations of await cds.connect.to('db')
db.entities
issue was also reported in https://answers.sap.com/questions/13051405/cap-different-behavior-when-deploying-to-cf-and-ha.html
I was able to fix this issue for the local run with sqlite by adding:
"model": "db"
to the cds.requires.db section in the package.json
was able to get past the initial error by removing the ../common dependency
Yes, that's a workaround for the missing dependency
The issue with the ../common dependency is fixed with the latest @sap/cds-dk
3.0.0.
cds build
now removes such file dependencies in the generated gen/srv/package.json
.
Also, with latest @sap/cds
4.1.9, the disfunctional cds.entities
is fixed.
I cloned the repo and did
cds watch bookshop
. Openedhttp://localhost:4004
-- all good.Then followed only https://cap.cloud.sap/docs/advanced/deploy-to-cloud to deploy to the Bookshop example to my HDI in SCP Trial.
But in step https://cap.cloud.sap/docs/advanced/deploy-to-cloud#deploy-using-cf-push the command
failed:
Indeed, there is no folder
common
under thegen
, while thegen/srv/package.json
has it as a dependency: