aws-amplify / amplify-cli

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

Lock file is removed from `amplify pull` #13283

Open neuquen opened 1 year ago

neuquen commented 1 year ago

Amplify CLI Version

12.5.1

Question

I recently needed to override some project-level config and followed this documentation in order to do so.

Running amplify override project generated a amplify/backend/package.json file in order to include dependencies needed to execute the generated amplify/backend/awscloudformation/overrides.js file. Our app uses yarn (v3) to manage its own dependencies, but we decided to manage amplify dependencies separately using NPM. So, within amplify/backend I ran npm install in order to include the needed dependencies which generated amplify/backend/package-lock.json and pushed it all up with amplify push. No issues there.

However, when I pull using amplify pull, it removes the amplify/backend/package-lock.json file and it throws this error:

āœ– There was an error initializing your environment.
šŸ›‘ Packaging overrides failed.
Command failed with exit code 1: yarn install
Usage Error: The nearest package directory (/Users/<me>/repos/app/amplify/backend) doesn't seem to be part of the project declared in /Users/<me>/repos/app.

- If /Users/<me>/repos/app isn't intended to be a project, remove any yarn.lock and/or package.json file there.
- If /Users/<me>/repos/app is intended to be a project, it might be that you forgot to list amplify/backend in its workspace configuration.
- Finally, if /Users/<me>/repos/app is fine and you intend amplify/backend to be treated as a completely separate project (not even a workspace), create an empty yarn.lock file in it.

If I try to pull using option 3 (creating an empty yarn.lock file), both the npm lock file AND the yarn lock file are removed and I see the same error. So I'm hoping you can answer the following questions:

  1. Why are my amplify/backend/package-lock.json and empty amplify/backend/yarn.lock files being removed when I pull?
  2. What is the recommended approach to running an amplify project using npm within an app that uses yarn (v3)? Should I be adding an empty yarn.lock file as yarn suggests or is there some other recommended approach?
ykethan commented 1 year ago

Hey @neuquen, thank you for reaching out. I was able to reproduce the issue. marking as bug.

Reproduction steps:

  1. amplify init
  2. amplify override project
  3. In my case the yarn.lock file was created by default, removed the yarn.lock file and the node_modules folder.
  4. ran npm install and amplify push -> no errors
  5. ran amplify pull this removed the node_modules and package-lock.json. Due to this the Cannot find module '@aws-amplify/cli-extensibility-helper' or its corresponding type declarations. occurs in the override file.
neuquen commented 1 year ago

Thanks @ykethan!

In my case the yarn.lock file was created by default

I didn't see this behavior when running the override project command. Any reason why the yarn.lock file was not generated for me? Also, if you don't remove the yarn.lock file, do you find that an amplify pull deletes that file as well?

ykethan commented 1 year ago

@neuquen I did observe a similar behavior with yarn.lock file as well.

Amplify CLI currently does not support utilizing yarn 3 which is causing the error message on overrides, the feature request is currently being tracked on https://github.com/aws-amplify/amplify-cli/issues/13178

Could you try utilizing an older version of yarn for example 1.22.19 and ensure the $PATH environment variable has been configured? For example, we can run which yarn on the terminal for MacOS to confirm if the yarn has been configured on the variable. Information on setting up the path

neuquen commented 1 year ago

Thanks for the response @ykethan.

We were able to find a temporary workaround for our situation. Whenever we pull, we temporarily add a /amplify/.yarnrc.yml file (with an empty yarnPath: "" included) and then remove it once the pull is done.

We'll use that in the meantime because we'd rather wait until yarn 3 is supported.