cancel
Showing results for 
Search instead for 
Did you mean: 

CDS Typer: @cds-models folder not generated

MioYasutake
Active Contributor
0 Kudos

Hi community,

I have enabled CDS Typer in my project by `cds add typer` followed by `npm i`. Event handler imports the model type by:

const { Questions } = require('#cds-models/fullstack_dev_challenge')

However, @cds-models folder was not generated and therefor execution failed with Error: Cannot find module '/.../fullStackDevChallenge/@cds-models/fullstack_dev_challenge/index.js'.

I have tried modifying .cds files, but it did not trigger the creation of @cds-models. How can I generate the @cds-models folder ?

package.json

{
  "name": "fullstackDevChallenge",
  "version": "1.0.0",
  "description": "A simple CAP project.",
  "repository": "<Add your repository here>",
  "license": "UNLICENSED",
  "private": true,
  "dependencies": {
    "@sap/cds": "^7",
    "express": "^4"
  },
  "devDependencies": {
    "sqlite3": "^5",
    "@cap-js/cds-typer": "^0"
  },
  "scripts": {
    "start": "cds-serve"
  },
  "imports": {
    "#cds-models/*": "./@cds-models/*/index.js"
  }
}

link to my repo (branch: typeScript) : https://github.com/miyasuta/fullstackDevChallenge

Regards,

Mio

View Entire Topic
Trulov
Participant

Hi mioyasutake,

Make sure that your VSCode Extension is properly configured:

  1. Go to your settings (CMD + ,) and search for "@ext:SAPSE.vscode-cds type generator".
  2. There, enable the Type Generator as in the image below.
  3. Make sure that @cap-js/cds-typer is installed, maybe restart VSCode.

The manual way: Of course you can always use a custom script for type generation, although it's not as comfortable as generating types automatically when saving .cds files. In your package.json insert the following script and run it with npm run build:models.

{
"scripts": {
"build:models": "npx @cap-js/cds-typer '*' --outputDirectory @cds-models"
}
}

If you're using Typescript, make sure that your tsconfig.json is setup correctly.
Example config:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "skipLibCheck": true,
    "outDir": "./gen/srv/srv",
    "noErrorTruncation": true,
    "moduleResolution": "nodenext",
    "paths": {
      "#cds-models/*": ["./@cds-models/*/index.ts"]
    }
  },
  "include": ["srv"],
  "exclude": ["node_modules"]
}


Best Regards
Tom