aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 821 forks source link

amplify always chooses the wrong package manager #13931

Open thegrandpoobah opened 22 hours ago

thegrandpoobah commented 22 hours ago

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

16.20.2

Amplify CLI Version

12.12.6

What operating system are you using?

Linux (and Windows WSL)

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No

Describe the bug

amplify push (or pull) always chooses yarn for me (and pnpm for a developer on my team) even though the package manager we've been using is npm and there is a package-lock.json file in the repo.

We've been away from this project for a couple months and we haven't made ANY changes to the repo/project/amplify and this behaviour just started when we upgraded our amplify. Not sure which version we were running prior.

Expected behavior

Use npm as was being done before.

Reproduction steps

just type amplify pull or amplify push on our project that has a package-lock.json in the root Please note: there is not a yarn.lock file anywhere to be seen in this amplify project folder structure. I have made tripley sure of this.

Project Identifier

f692ebb27a73e75af29c87f79f8db1e0

Log output

Fetching updates to backend environment: dev from the cloud.⠋ Building resource api/AdminQuerie⠼ Building resource api/lambdaserverlessadmi⚠️ WARNING: owners may reassign ownership for the following model(s) and role(s): Profile: [owners], Customer: [owners]. If this is not intentional, you may want to apply field-level authorization rules to these fields. To read more: https://docs.amplify.aws/cli/graphql/authorization-rules/#per-user--owner-based-data-access. ⠦ Building resource api/lambdaserverlessadmi✅ GraphQL schema compiled successfully.

Edit your schema at /amplify/backend/api/lambdaserverlessadmi/schema.graphql or place .graphql files in a directory at /amplify/backend/api/lambdaserverlessadmi/schema ✖ Fetching updates to backend environment: dev from the cloud. ✖ There was an error initializing your environment. 🛑 Packaging overrides failed. Command failed with exit code 1: yarn install warning package.json: No license field warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json. ... and lots more yarn failures

Additional information

I fixed this by deleting yarn from my computer. My colleague fixed it by renaming her pnpm binary.

Before submitting, please confirm:

ykethan commented 21 hours ago

Hey @thegrandpooba, thank you for reaching out. It appears the behavior is occurring due to following https://github.com/aws-amplify/amplify-cli/blob/a644a1f1577c29567c1b6986cc6041ef99623219/packages/amplify-cli-core/src/utils/packageManager.ts#L109-L118

To mitigate the issue you could try removing the yarn.lock and node_modules from the amplify/backend directory then install using your preferred package manager in the amplify/backend which should switch the package manager.

thegrandpoobah commented 21 hours ago

Thanks for your note, but I do not have yarn.lock file anywhere in my repository (i have now quadruple checked). There is only package-lock.json. It also doesn't explain why it picks pnpm for my colleauge (no pnpm-lock.yaml in this repository either)