question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blocked by constant issues with node-gyp-build

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:23 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
rafaelfariacommented, Nov 15, 2022

@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.

1reaction
rafaelfariacommented, Nov 8, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solving common issues with node-gyp - LogRocket Blog
Many node-gyp issues are actually issues with the toolchain used for building add-on code. We'll categorize these issues to offer solutions.
Read more >
npm install <module> persistent error ? (node-gyp build ?)
I too was having consistent issues with installation and for me it was the default version of node that I was on (0.11.13-beta)....
Read more >
`node-gyp` (nodejs 12) fails in GitLab CI (#356662) · Issues
node -gyp fails in GitLab CI with the below error when running for nodejs12. The same build works when executed directly in a...
Read more >
T213944 Jenkins jobs for npm-test fail on project with deps on ...
Mainly because Most jessie/node6 jobs already have py27 (we've been using node-gyp in dev dependencies for years without issue). But also, because if...
Read more >
Node.js v19.3.0 Documentation
Node-API. Implications of ABI stability; Building. Build tools. node-gyp; CMake.js ... Report errors in this documentation in the issue tracker.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found