amplify-backend icon indicating copy to clipboard operation
amplify-backend copied to clipboard

When running a separate Frontend from your Backend the backend-cli has unmet peer dependencies

Open JDMathew opened this issue 1 year ago • 4 comments

Environment information

- unable to run `npx ampx info` as peer dependencies are missing

Description

When running a separate frontend from B.E on react-native the docs require one to install @aws-amplify/backend-cli this results in unmet peer dependencies and npx ampx commands fail to run as there are a number of missing dependencies

image

JDMathew avatar Jun 04 '24 06:06 JDMathew

Hi @JDMathew, this happens due to how different package managers deal with unmet peer dependencies. npm and pnpm will automatically resolve and install them. yarn has taken the stance that it will not install unmet peer dependencies and they must be explicitly added to your package.json file. See https://github.com/yarnpkg/berry/issues/3710. If you are using yarn, you can add the missing peer dependencies to your package.json file.

A bit more context about why these packages are peer dependencies: You'll notice all of the dependencies are either CDK or AWS SDK packages. These packages contain types / classes that are re-exported in various places in our Amplify interfaces. In order to ensure that both our code and the calling code is using the same version of these packages, they must be peer dependencies rather than normal dependencies.

edwardfoyle avatar Jun 04 '24 16:06 edwardfoyle

@edwardfoyle, I appreciate the detailed response, the context is useful. I will install these dependencies.

Since most React Native developers use yarn as their package manager (previously recommended by facebook), it would be useful if instructions were added to the docs for adding these devDependencies for yarn consumers. Here is a link to the doc I was following for 'Separate frontend and backend teams'.

On a related note, the docs currently require adding @aws-amplify/backend-cli as dependency with aws-amplify and @aws-amplify/ui-react. @aws-amplify/backend-cli should probably be added as a dev dependency and not a regular dependency. That way it isn't bundled up in the final app build.

JDMathew avatar Jun 04 '24 19:06 JDMathew

Yes, we should call this out in the docs. And thanks for bringing up the devDependency issue; that also needs to be corrected. Marking as a docs issue

edwardfoyle avatar Jun 04 '24 23:06 edwardfoyle

Hey @JDMathew to understand your project setup better, is this a monorepo? Are you looking to use the backend CLI in your react-native app's package?

josefaidt avatar Jun 06 '24 00:06 josefaidt