Skip to Content
Jan 25 at 03:18 PM

CDS Serve - Paths



I have a CAP app that is written in TS. As the code growths, the import paths started to be really long as it would be something like import { Service} from ../../../../module/service. I looked for a solution for this and there seems to be an option for TS to define paths. This is what I have in tsconfig.js.

"baseUrl": "./",
"paths": {
"@/*": [

This allows me to have absolute import parts like this.

import * as pp from "@/srv/model/rsag.pp";

This seems to work OK for VSCode and tsc. VSCode code navigation works with this, I can Ctrl+click on the path and it opens the correct file. I can also run tsc and it correctly compiles the whole project. The problem is that when I am running cds-ts serve or cds serve in the build folder, it fails on the following error:

[ERROR] Cannot find module '@/srv/module/service'.

As an alternative, I tried also absolute path "srv/moule/service" but with the same result, tsc and VSCode are happy, cds not.

Is this supported? How can I make this work as it makes import statements easier to read.