aws-amplify / aws-amplify/amplify-cli
codegen generates inconsistent casing for Enum models in v13.0.1 causing ReferenceError
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
### How did you install the Amplify CLI?
npm
### If applicable, what version of Node.js are you using?
20.19.2
### Amplify CLI Version
13.0.1
### What operating system are you using?
Windows
### Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No manual changes were made. This issue is reproducible after a fresh installation of Amplify CLI v13.0.1 and running `amplify codegen models`.
### Describe the bug
When running `amplify codegen models`, the generated file at `src/models/index.js` contains a `ReferenceError`.
The generator creates JavaScript constants for GraphQL enums with PascalCasing (e.g., `const RtcRecordType = { ... }`), but the `export` statement at the end of the file tries to export them using a different, uppercase casing (e.g., `export { RTCRecordType }`). This causes the application build to fail because the exported identifier does not exist.
This issue started occurring immediately after upgrading from `@aws-amplify/cli@13.0.0` to `@aws-amplify/cli@13.0.1`. Downgrading back to `13.0.0` and regenerating models resolves the issue, confirming it's a regression in the latest version.
### Expected behavior
The `export` statement in `src/models/index.js` should use the same variable names that are defined within that file, so that no `ReferenceError` occurs and the application can build successfully.
For example, if the generator creates `const RtcRecordType`, it should also export `RtcRecordType`, not `RTCRecordType`.
### Reproduction steps
1. Use `@aws-amplify/cli` version `13.0.1`.
2. Define a GraphQL schema (`schema.graphql`) that contains an enum with an uppercase acronym, like `RTC`.
3. Run the `amplify codegen models` command.
4. Try to build the Vue application (e.g., using `pnpm run dev` with Vite).
5. The build will fail with a `ReferenceError` originating from `src/models/index.js`.
### Project Identifier
_No response_
### Log output
```
# Put your logs below this line
Error: Failed to scan for dependencies from entries:
C:/my-path/index.html
X [ERROR] "RTCRecordDetailType" is not declared in this file
src/models/index.js:221:2:
221 │ RTCRecordDetailType,
╵ ~~~~~~~~~~~~~~~~~~~
X [ERROR] "RTCRecordDetailDataType" is not declared in this file
src/models/index.js:222:2:
222 │ RTCRecordDetailDataType,
╵ ~~~~~~~~~~~~~~~~~~~~~~~
X [ERROR] "RTCRecordType" is not declared in this file
src/models/index.js:223:2:
223 │ RTCRecordType,
```
### Additional information
_No response_
### Before submitting, please confirm:
- [x] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [x] I have removed any sensitive information from my code snippets and submission.
Contributor guide
Research direction
Start by reproducing `amplify codegen models` with a `schema.graphql` enum containing an uppercase acronym, then inspect the generated `src/models/index.js` and compare it with output from CLI 13.0.0. Done means the exported identifiers match the generated constants and the Vue application builds successfully with `pnpm run dev`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, javascript, typescript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100