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

Lock file is removed from `amplify pull`

Open neuquen opened this issue 2 years ago • 5 comments

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?

neuquen avatar Sep 29 '23 19:09 neuquen

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.

ykethan avatar Oct 03 '23 16:10 ykethan

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?

neuquen avatar Oct 03 '23 18:10 neuquen

@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

ykethan avatar Oct 03 '23 19:10 ykethan

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.

neuquen avatar Oct 10 '23 21:10 neuquen

The year is 2025, and this is still a problem that's biting people, including us.

armenr avatar May 26 '25 14:05 armenr

I hit this issue recently and I'm spending hours trying to come up with a proper no hack solution to continue my day. It's just not fun fighting with the build tools because the Amplify team has not been cable of fixing this bug for close to 2 years.

Are there any new workaround, considering that this bug seems to not have been fixed yet.

houmark avatar Aug 01 '25 09:08 houmark