cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CAP Typescript - Error - Could not find a declaration file for module '@sap/cds'

sandeepmalhotra
Participant
3,151

Hello Everyone 

I am using typescript with CAP

After upgrading to new version, I start getting following error

Could not find a declaration file for module '@sap/cds'. '/project/node_modules/@sap/cds/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/sap__cds` if it exists or add a new declaration (.d.ts) file containing `declare module '@sap/cds';`ts(7016)

for statement

import cds from "@sap/cds";
 
Version details
 
@cap-js/asyncapi: 1.0.1
@cap-js/cds-typer: 0.24.0
@cap-js/openapi: 1.0.4
@cap-js/sqlite: 1.7.1
@Sisn/cds: 8.0.3
@Sisn/cds-compiler: 5.0.6
@Sisn/cds-dk: 8.0.2
@Sisn/cds-dk (global): 8.0.2
@Sisn/cds-fiori: 1.2.7
@Sisn/cds-foss: 5.0.1
@Sisn/cds-hana: 2.0.0
@Sisn/cds-mtxs: 2.0.2
@Sisn/cds-odata-v2-adapter-proxy: 1.9.21
@Sisn/eslint-plugin-cds: 3.0.4
Node.js: v20.13.1
 
Also getting error  Cannot find name **** (2304)  for SELECt,DELETE,UPDATE statements
 
Kindly let me know how to fix it 

 

Accepted Solutions (1)

Accepted Solutions (1)

Trulov
Participant

Hi @sandeepmalhotra ,

the types have moved to the cap-js/cds-types package. So just install it via `npm i -D @cap-js/cds-types` and there you have all your types in one .d.ts file.

BR Tom

Matthias_Kolley
Explorer
0 Kudos
With Version 0.8.0 this error occurs again. So i reverted back to 0.6.5
thomolka1
Newcomer
I've encountered the problem also for cds-8.6.0. I spent some time to analyze it and what helped me was to add the following script to package.json file: "postinstall": "test -L node_modules/@types/sap__cds || ln -s ../@cap-js/cds-types node_modules/@types/sap__cds" (works on linux/macos systems)

Answers (2)

Answers (2)

jasonmuzzy
Active Participant

This seems to be a known issue.  For me, running npm rebuild resolved it.  See https://cap.cloud.sap/docs/get-started/troubleshooting#typescript.

Type definitions for @SAP/cds not found or incomplete

  Explanation

Root Cause 1The package @cap-js/cds-typer is not installed.
Solution 1Install the package as a dev dependency.
Root Cause 2Symlink is missing.
Solution 2Try npm rebuild or add @cap-js/cds-types in your tsconfig.json.
WouterLemaire
SAP Mentor
SAP Mentor
0 Kudos

Do you use cds-ts to run commands? Otherwise, try the reply from @brian_keenan here: https://community.sap.com/t5/technology-q-a/facing-error-while-building-and-watching-cap-project/qaq...