Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to amplify build function when using yarn 3 #13001

Closed
2 tasks done
ginobean opened this issue Jul 25, 2023 · 7 comments
Closed
2 tasks done

unable to amplify build function when using yarn 3 #13001

ginobean opened this issue Jul 25, 2023 · 7 comments
Assignees
Labels
bug Something isn't working functions Issues tied to the functions category p1

Comments

@ginobean
Copy link

How did you install the Amplify CLI?

npm

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

16.19.1

Amplify CLI Version

12.2.0

What operating system are you using?

Ubuntu

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

No

Describe the bug

I used 'amplify add function' to add a lambda, with the default 'Hello World' js option.

Then, I tried to run 'amplify function build', and got this error:

Packaging lambda function failed with the error 
Command failed with exit code 1: yarn install
Usage Error: The nearest package directory (/home/gino/local/amplify-app/amplify/backend/function/foobar/src) doesn't seem to be part of the project declared in /home/gino/local/amplify-app.

BTW, as a side note, in trying to resolve this issue, I noticed that the package.json, for the lambda function, was in the src subdirectory for the function. Out of curiosity, I tried moving package.json to the parent of src directory, e.g. 'mv package.json ..' . And 'amplify add function' no longer errored out. Not sure if this is the correct resolution..

I believe 'amplify push' also yields the exact same error message as 'amplify add function'. And moving the package.json, for the lambda function, from the src subdir to the parent of the src directory, 'mv package.json ..' also seemed to enable 'amplify push' to work correctly.

Expected behavior

Expection is that the function would be built correctly.

Reproduction steps

See the bug description for the reproducible steps.

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@ginobean ginobean added the pending-triage Issue is pending triage label Jul 25, 2023
@josefaidt
Copy link
Contributor

Hey @ginobean 👋 thanks for raising this! Out of curiosity what version of yarn are you using? Is there a workspaces setting that is picking up this directory?

@josefaidt josefaidt added pending-response Issue is pending response from the issue author functions Issues tied to the functions category labels Jul 25, 2023
@ginobean
Copy link
Author

yarn 3.5.0
Could not find any workspaces setting that is picking up the lambda related directory.

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Jul 25, 2023
@josefaidt
Copy link
Contributor

Hey @ginobean thanks for clarifying! I'm not able to reproduce with the latest yarn berry release and amplify add function. Would you mind sharing the full command execution output? I'm curious if there is some setting or prompt that is triggering this

@josefaidt josefaidt added the pending-response Issue is pending response from the issue author label Jul 25, 2023
@josefaidt
Copy link
Contributor

Hey @ginobean I was able to reproduce this by running amplify build

➜  amplify build function
✔ Are you sure you want to continue building the resources? (y/N) · yes
🛑 Packaging lambda function failed with the error 
Command failed with exit code 1: yarn install
➤ YN0070: Migrating from Yarn 1; automatically enabling the compatibility node-modules linker 👍

Usage Error: The nearest package directory (/Users/josef/Documents/projects/aws-amplify/reproductions/12881/amplify/backend/function/1288141ced489/src) doesn't seem to be part of the project declared in /Users/josef/Documents/projects/aws-amplify/reproductions/12881/amplify/backend.

However the error is also printing suggestions that seem like a reasonable solution:

...
- Finally, if /Users/josef/Documents/projects/aws-amplify/reproductions/12881/amplify/backend is fine and you intend function/1288141ced489/src to be treated as a completely separate project (not even a workspace), create an empty yarn.lock file in it.

Although after creating empty yarn.lock files I am presented with a different error:

➜  amplify build function
✔ Are you sure you want to continue building the resources? (y/N) · yes
🛑 Received error [Error: Command failed with exit code 1: yarn --no-bin-links --production
Unknown Syntax Error: Unsupported option name ("--no-bin-links").

This appears to be failing to resolve the correct yarn version to change the install command https://github.com/aws-amplify/amplify-cli/blob/dev/packages/amplify-cli-core/src/utils/packageManager.ts#L148-L152

Marking as a bug

@josefaidt josefaidt added bug Something isn't working p1 and removed pending-response Issue is pending response from the issue author pending-triage Issue is pending triage labels Jul 25, 2023
@josefaidt josefaidt changed the title 'amplify add function' seems to be broken unable to amplify build function when using yarn 3 Jul 28, 2023
@jhockett jhockett added the pending-release Code has been merged but pending release label Aug 17, 2023
@sobolk sobolk removed the pending-release Code has been merged but pending release label Nov 9, 2023
@codenimble
Copy link

+1 See also #13377

@0618
Copy link
Contributor

0618 commented Jan 23, 2024

The error happens because Modern Yarn (2,3) doesn't create yarn.lock when running yarn install if it can find a yarn.lock in it's parent directory.

Before the PR #13197 gets merged, we can manually do a workaround to create a yarn.lock in the amplify directory. It should solve the problem.

Copy link

github-actions bot commented May 1, 2024

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working functions Issues tied to the functions category p1
Projects
None yet
Development

No branches or pull requests

6 participants