Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] A generated index.ts files has syntax errors "Duplicate Identifier ..." #288

Open
1 task done
D027152 opened this issue Jul 31, 2024 · 9 comments
Open
1 task done
Labels
bug Something isn't working keepalive Will not be closed by Stale bot

Comments

@D027152
Copy link

D027152 commented Jul 31, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Nature of Your Project

TypeScript

Current Behavior

When generating files in @cds-models, one of the generated files has syntac errors. e.g.

Cannot redeclare exported variable '_PaymentAgreementOutgoingAspect'.
Duplicate function implementation.
Duplicate identifier 'PaymentAgreementOutgoing'.
Class 'PaymentAgreementOutgoing' used before its declaration.

The file is this one: https://github.tools.sap/erp4sme/crypto-for-business/blob/switch-to-cds-typer-payment-master-data/%40cds-models/sap/erp4sme/c4b/masterData/businessPartners/index.ts

Expected Behavior

Files are generated without syntax errors

Steps To Reproduce

repo https://github.tools.sap/erp4sme/crypto-for-business
branch switch-to-cds-typer-payment-master-data
above-mentioned files are located in https://github.tools.sap/erp4sme/crypto-for-business/tree/switch-to-cds-typer-payment-master-data/%40cds-models)

to re-generate the files run npm run cds-typer:dev

Environment

| c4b                    | github.tools.sap/erp4sme/crypto-for-business.git                           |
| ---------------------- | -------------------------------------------------------------------------- |
| @cap-js/audit-logging  | 0.8.0                                                                      |
| @cap-js/cds-types      | 0.2.0                                                                      |
| @cap-js/change-trackin | 1.0.6                                                                      |
| @cap-js/telemetry      | 0.2.3                                                                      |
| @sap/cds               | 7.9.4                                                                      |
| @sap/cds-common-conten | 2.0.0                                                                      |
| @sap/cds-compiler      | 4.9.4                                                                      |
| @sap/cds-dk            | 7.9.6                                                                      |
| @sap/cds-dk (global)   | 7.7.2                                                                      |
| @sap/cds-fiori         | 1.2.3                                                                      |
| @sap/cds-foss          | 5.0.0                                                                      |
| @sap/cds-mtxs          | 2.0.3                                                                      |
| @sap/eslint-plugin-cds | 3.0.4                                                                      |
| Node.js                | v18.18.0                                                                   |
| home                   | /Users/D027152/Documents/git/dch/crypto-for-business/node_modules/@sap/cds |

npx cds-typer --version: 0.23.0

Repository Containing a Minimal Reproducible Example

https://github.tools.sap/erp4sme/crypto-for-business

Anything else?

This is a follow-up for bug #278

@hakimio
Copy link

hakimio commented Aug 7, 2024

Possibly related issues: #139 #144

@daogrady daogrady removed the new label Sep 3, 2024
Copy link

github-actions bot commented Oct 3, 2024

This issue has not been updated in a while. If it is still relevant, please comment on it to keep it open. The issue will be closed soon if it remains inactive.

@github-actions github-actions bot added the stale label Oct 3, 2024
@daogrady daogrady added keepalive Will not be closed by Stale bot and removed stale labels Oct 7, 2024
@georgianjalba
Copy link

Hey, just checked and if I upgrade from version 0.25.0 to any newer version ( 0.26.0 or 0.27.0 ) I have this duplicate identifier issue.
The issue is easily reproducible by having a service and an entity in the service with the same name as the service.
As I know changing the name would normally fix the issue we have no control over the names of either the service or the entity so we need to find an alternate way of fixing this.

Would be awesome if a workaround/config we could do would exist or better yet a planned fix :P

Thanks for the help and keep up the good work!

@daogrady
Copy link
Contributor

daogrady commented Oct 9, 2024

Hi @georgianjalba ,

thanks for investigating the root cause of this issue. In that case you should be able to circumvent the collision by specifying a custom singular and plural name (not: changing the actual name) for the offending entity:

service X {
    @singular: 'XEntity'
    @plural: 'XEntities'
    entity X {}
}

Let me know if that helps.

Best,
Daniel

@D027152
Copy link
Author

D027152 commented Oct 10, 2024

Hi @georgianjalba @daogrady

The problem I described above is not related to the situation that @georgianjalba describes, as far as I can see. However, I just recognised that with cds-typer 0.27.0 this problem does no longer occur (I created this issue based on 0.23.0).

I also face a similar issue as @georgianjalba describes: two entities in the same service, both having an association to an entity called "ActivationStatusCodes", but the first associated entity is in namespace sap.erp4sme.c4b.masterData.integrations, the second is in namespace sap.erp4sme.c4b.masterData.businessPartners. This gave a duplicate identifier error, which I was able to overcome by specifying different deviating custom singular and plural names ('IntegrationActivationStatusCodes' and 'BusinessPartnerActivationStatusCodes').

@daogrady
Copy link
Contributor

Hi @D027152 ,

thanks for the update on your situation! Does that mean the issue is resolved?

Best,
Daniel

@D027152
Copy link
Author

D027152 commented Oct 11, 2024

Hi @daogrady

I don't have an issue any longer. But I understood that the solution with the singular / plural annotations is rather a workaround than a solution. However, if this is from your point of view a final solution, then I would just expect in a documentation a note that this is what someone shall do when he/she rund into the problem of duplicate identifiers.

Best regards,
Stefan

@daogrady
Copy link
Contributor

daogrady commented Oct 21, 2024

@chgeo fyi please provide minimal repro that made the introduction of named service exports necessary.

@chgeo
Copy link
Member

chgeo commented Nov 15, 2024

@daogrady Here is the demo project: https://github.com/chgeo/issue-named-service-exports
See its readme for further details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working keepalive Will not be closed by Stale bot
Projects
None yet
Development

No branches or pull requests

5 participants