on 09-14-2023 9:26 PM
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
Hi mioyasutake,
Make sure that your VSCode Extension is properly configured:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
72 | |
8 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.