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

Amplify Push Failed after amplify add function #7883

Closed
4 tasks done
dan0nator opened this issue Aug 4, 2021 · 15 comments · Fixed by #8263
Closed
4 tasks done

Amplify Push Failed after amplify add function #7883

dan0nator opened this issue Aug 4, 2021 · 15 comments · Fixed by #8263
Assignees
Labels
bug Something isn't working functions Issues tied to the functions category

Comments

@dan0nator
Copy link

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

How did you install the Amplify CLI?

yarn

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

14.15.5

Amplify CLI Version

5.2.1

What operating system are you using?

Windows 10 Pro

Amplify Categories

function

Amplify Commands

push

Describe the bug

When pushing to amplify I get the following error:

Packaging lambda function failed with the error
Command failed with exit code 1: yarn.cmd --production
➤ YN0050: The --production option is deprecated on 'install'; use 'yarn workspaces focus' instead
An error occurred during the push operation: Packaging lambda function failed with the error
Command failed with exit code 1: yarn.cmd --production
➤ YN0050: The --production option is deprecated on 'install'; use 'yarn workspaces focus' instead

if I remove the function with "amplify remove function" it will push without issue.
I can pull without issue as well.

Expected behavior

It should push without error.

Reproduction steps

amplify add function
complete steps to add function (vanilla) nothing but defaults.
amplify push

GraphQL schema(s)

# Put schemas below this line

Log output

# Put your logs below this line


Additional information

No response

@jhockett
Copy link
Contributor

jhockett commented Aug 4, 2021

Hi @dan0nator, what version of yarn are using?

--production should work with yarn classic (1.x). https://classic.yarnpkg.com/en/docs/cli/install/#toc-yarn-install-production-true-false

@dan0nator
Copy link
Author

yarn version 2.4.1 - i have not updated the yarn version, but i did update the amplify API

@jhockett jhockett added functions Issues tied to the functions category bug Something isn't working labels Aug 4, 2021
@jhockett jhockett added the dependency-issue Issue with another dependency used label Aug 4, 2021
@romeubertho
Copy link

romeubertho commented Aug 12, 2021

I'm having a similar issue. But my problem with amplify push using --production flag is that I cannot use devDependencies to build (docs) my lambda or packages using babel because devDependencies are not installed.

In version 5.2.0 and below, I didn't have the issue above, but each lambda function/layer has devDependencies inside their node_modules.

Can/do we have something like SAM's building custom runtime in Amplify?

I checked the file legacyBuild.ts located in packages/amplify-nodejs-function-runtime/src/utils, and the issue seems to be in buildResource and installDependencies functions.
I would suggest the buildResource function having the following flow:

installDependencies(); // run yarn install and npm equivalent
runBuildScriptHook();
installDependencies(); // run yarn --production --frozen-lockfile --non-interactive --ignore-scripts and npm equivalent

This might solve the build and the devDependencies inside node_modules issues but won't solve the yarn v2 issue.

@adam-nygate
Copy link

For anyone else having this error when using yarn v2 for their project:

YN0050: The --production option is deprecated on 'install'; use 'yarn workspaces focus' instead

We fixed this with a simple workaround:

  • Create a shared .yarn/releases folder somewhere in the root of your project directory
  • Download a yarn v1 release to this directory (I.e. yarn set version classic)
  • Create a .yarnrc.yml in each of the Amplify Functions src directories(amplify/backend/function/**/src)
  • Tell yarn to use the v1 release via the yarnPath configuration key in the .yarnrc.yml (I.e. yarnPath: '../../../../../.yarn/releases/yarn-1.23.0.cjs')

@danielleadams danielleadams added the investigating This issue is being investigated label Sep 2, 2021
@MichaelKilbane
Copy link

Currently migrating a project to Yarn 2, and also running into this issue.

@adam-nygate thanks for the workaround. Hopefully, the fix isn't far away.

@danielleadams
Copy link
Contributor

danielleadams commented Sep 24, 2021

@dan0nator Yarn 2 isn't supported by Amplify CLI yet, so the workaround is the only way to do this right now. In the future, the CLI will have to detect usage of Yarn >= 2 when building the lambda to use the new yarn install --production command and the user's source code will also need to include the workspaces plugin (as of Yarn 3.0.1). I'll keep this open for now to create a more graceful error message, but this bug won't be fixed until Yarn 2 is officially supported.

@danielleadams danielleadams added bug Something isn't working and removed investigating This issue is being investigated bug Something isn't working dependency-issue Issue with another dependency used labels Sep 24, 2021
@gambithunt
Copy link

I've used npm to install modeules into my amplify layer function and I'm getting this error, I've never used yarn before with this project, why would I be getting this error? Also any idea how I can fix it?

@codybreene
Copy link

Hitting this same exact issue @gambithunt , why is this closed?

@nomadev21
Copy link

On ubuntu 20.04, running sudo apt remove cmdtest fixed it!

@gentritbiba
Copy link

On ubuntu 20.04, running sudo apt remove cmdtest fixed it!

THANK YOU! This fixed it for me as well

@gawshan
Copy link

gawshan commented Jan 29, 2022

worked for me too after running sudo apt remove cmdtest

@kretep
Copy link

kretep commented Feb 9, 2023

I got it to work by temporarily switching to the old yarn with yarn set version classic and then switch back to yarn set version berry after pushing with amplify.

@andy-rsa
Copy link

This error has returned. It started 2 days ago using the latest cli when doing "amplify push" after "amplify add function"

YN0050: The --production option is deprecated on 'install'; use 'yarn workspaces focus' instead

@andy-rsa
Copy link

This error has returned. It started 2 days ago using the latest cli when doing "amplify push" after "amplify add function"

YN0050: The --production option is deprecated on 'install'; use 'yarn workspaces focus' instead

navigating to the directory that holds the function and running "npm install" installed the requisite modules. Running "amplify configure" after that first step worked.

@rafaelfaria
Copy link

This is still a problem (for me). I have almost 30 functions, not scalable to use the workaround suggested 3 years ago. Is there any other way to do this? And is there any reason why this hasn't been fixed yet? we have yarn v3 now. Thanks

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
Projects
None yet