amplify-cli: Blocked by constant issues with node-gyp-build

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.
  • I have removed any sensitive information from my code snippets and submission.

How did you install the Amplify CLI?

npm

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

v16.17.0

Amplify CLI Version

10.3.2

What operating system are you using?

Mac

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

No manual changes made

Amplify Categories

Not applicable

Amplify Commands

push

Describe the bug

Ever since I updated to the latest version of amplify I have been getting into issues with either symlinks or node-gyp-build.

Lately, I have been using a lambda function that uses web3, however, I have come to so many issues, that I decided to move away from it. Even locally, where this suggestion should’ve worked, it’s not working anymore.

I thought moving away from web3 would have worked. However, I still keep getting into issues when deploying my lambda layer. Here it’s the latest message:

2022-10-30T12:49:40.241Z [INFO]: 🛑 Packaging lambda function failed with the error
                                 Command failed with exit code 127: yarn --no-bin-links --production
                                 warning package.json: No license field
                                 warning No license field
                                 error /codebuild/output/src759146275/src/myapp/amplify/backend/function/cryptoappCommonLayer/lib/nodejs/node_modules/bufferutil: Command failed.
                                 Exit code: 127
                                 Command: node-gyp-build
                                 Arguments:
                                 Directory: /codebuild/output/src759146275/src/myapp/amplify/backend/function/cryptoappCommonLayer/lib/nodejs/node_modules/bufferutil
                                 Output:
                                 /bin/sh: node-gyp-build: command not found
                                 yarn install v1.22.0
                                 [1/4] Resolving packages...
                                 [2/4] Fetching packages...
                                 [3/4] Linking dependencies...
                                 [4/4] Building fresh packages...
                                 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
2022-10-30T12:49:40.241Z [INFO]: Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

I don’t have bufferutils on my package so it might be some sort of dependency from one of the packages.

The issue is SO bizarre, that the SAME code, everything EXACTLY the same, merged into 2 branches, but running into 2 different environments (one for prod and another one for dev). Gives a completely different issue

2022-10-31T12:00:37.138Z [INFO]: Suggested configuration for new layer versions:
2022-10-31T12:00:37.138Z [INFO]: 
2022-10-31T12:00:37.140Z [INFO]: cryptoappCommonLayer
                                   - Access permissions: Maintain existing permissions
                                   - Description: Updated layer version  2022-10-31T12:00:37.138Z
2022-10-31T12:00:37.140Z [INFO]: 
2022-10-31T12:00:56.049Z [WARNING]: ✖ There was an error initializing your environment.
2022-10-31T12:00:56.173Z [INFO]: 🛑 Packaging lambda function failed with the error
                                 Command failed with exit code 127: yarn --no-bin-links --production
                                 warning package.json: No license field
                                 warning No license field
                                 error /codebuild/output/src773265498/src/myapp/amplify/backend/function/cryptoappCommonLayer/lib/nodejs/node_modules/utf-8-validate: Command failed.
                                 Exit code: 127
                                 Command: node-gyp-build
                                 Arguments:
                                 Directory: /codebuild/output/src773265498/src/myapp/amplify/backend/function/cryptoappCommonLayer/lib/nodejs/node_modules/utf-8-validate
                                 Output:
                                 /bin/sh: node-gyp-build: command not found
                                 yarn install v1.22.0
                                 [1/4] Resolving packages...
                                 [2/4] Fetching packages...
                                 [3/4] Linking dependencies...
                                 [4/4] Building fresh packages...
                                 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
2022-10-31T12:00:56.173Z [INFO]: Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

Expected behavior

I would expect to be deployed without me worrying if there is a symlink or not. Or the requirement of.a node-gyp-build.

Reproduction steps

I actually not sure how to reproduce this because I am not sure how to narrow down the packaged which needs to be installed in order to get this error.

GraphQL schema(s)

# Put schemas below this line


Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 32 (10 by maintainers)

Most upvoted comments

Edit I made it work with the following workaround -> just install the package that is producing the issue globally prior to any other steps that are written here in this thread…

amplify.yml

version: 1
backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - yarn global add node-pre-gyp@0.17.0
        - cd amplify/backend/function/bpr2lambda1/src && yarn install && cd -
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - yarn install --ignore-engines
    build:
      commands:
        - yarn run build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

Same issue here with node-pre-gyp. The package is built successfully when pushed with amplify push but when the Amplify CI/CD triggers then the follow error code 127 is issued.

@linglongguzi the suggestion @josefaidt mentioned above works for me. You need to yarn in the src folder (I’m using node 16).

However, still doesn’t work in the console. I’m waiting @josefaidt to give me some guidance here.

Hi @josefaidt

To clarify, are you still experiencing this issue in the Amplify Hosting builds after creating a lockfile for the affected layer/function?

Locally this indeed solved the problem, however, Amplify hosting still breaking.

In your buildspec (amplify.yml) file, add these lines to the preBuild phase before amplifyPush --simple. I would recommend ensuring the Node and Amplify CLI versions used by Amplify Hosting matches what you currently have installed locally.

I tried modifying the amplify.yml, and i didn’t see any changes, then I tried to edit it through the build settings, and the problem still persists.

Here is my amplify.yml. However, i don’t think its triggering the prebuild

version: 1
backend:
  phases:
    preBuild:
      commands:
        - nvm install 16
        - npm i -g @aws-amplify/cli
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
    build:
      commands:
        - yarn run build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

When the build happens I still get this in the “Cloning repository” phase:

2022-11-08T06:26:14.843Z [INFO]: # Node version 16 is available for installation
2022-11-08T06:26:15.011Z [INFO]: # Installing Node version 16
2022-11-08T06:26:22.099Z [INFO]: # Now using Node version 16
2022-11-08T06:26:23.183Z [WARNING]: Cannot find module '/root/.nvm/versions/node/v16.18.1/lib/node_modules/@aws-amplify/cli/package.json'
                                    Require stack:
                                    - /snapshot/AWSMobilePioneerExecute/out/index.js
2022-11-08T06:26:23.183Z [INFO]: # Patching NPM package '@aws-amplify/cli' to 10.4.0...
2022-11-08T06:26:30.589Z [INFO]: # Done patching NPM package '@aws-amplify/cli' to version 10.4.0

Then I still get the ERROR.

Did you manage to get it working? I’m a bit clueless on what to do next.