Installing third party libraries in Node.js on Google Cloud involves using the npm package manager

As I attempt to deploy my code on Google Cloud, everything runs smoothly during testing. However, when I execute the command:

gcloud app deploy

An error is displayed. Specifically, I am trying to install Node.js canvas which necessitates certain dependencies that are already installed in my application, yet the error persists. Below are the logs:

Step #1: > [email protected] preinstall /app/node_modules/extract-opts/node_modules/typechecker
Step #1: > node ./cyclic.js
Step #1:
Step #1:
Step #1: > [email protected] preinstall /app/node_modules/extendr/node_modules/typechecker
Step #1: > node ./cyclic.js
Step #1:
Step #1:
Step #1: > [email protected] install /app/node_modules/canvas
Step #1: > node-gyp rebuild
Step #1:
Step #1: ./util/has_lib.sh: 31: ./util/has_lib.sh: pkg-config: not found
Step #1: gyp: Call to './util/has_lib.sh freetype' returned exit status 0 while in binding.gyp. while trying to load binding.gyp
Step #1: gyp ERR! configure error 
Step #1: gyp ERR! stack Error: `gyp` failed with exit code: 1
Step #1: gyp ERR! stack     at ChildProcess.onCpExit (/nodejs/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:336:16)
Step #1: gyp ERR! stack     at emitTwo (events.js:126:13)
Step #1: gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
Step #1: gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
Step #1: gyp ERR! System Linux 4.4.0-116-generic
Step #1: gyp ERR! command "/nodejs/bin/node" "/nodejs/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
Step #1: gyp ERR! cwd /app/node_modules/canvas
Step #1: gyp ERR! node -v v8.10.0
Step #1: gyp ERR! node-gyp -v v3.6.2
Step #1: gyp ERR! not ok 
Step #1: npm WARN [email protected] No repository field.
Step #1: npm WARN The package reactstrap is included as both a dev and production dependency.
Step #1: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
Step #1: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
Step #1: 
Step #1: npm ERR! code ELIFECYCLE
Step #1: npm ERR! errno 1
Step #1: npm ERR! [email protected] install: `node-gyp rebuild`
Step #1: npm ERR! Exit status 1
Step #1: npm ERR! 
Step #1: npm ERR! Failed at the [email protected] install script.
Step #1: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Step #1: 
Step #1: npm ERR! A complete log of this run can be found in:
Step #1: npm ERR!     /root/.npm/_logs/2018-03-26T04_20_15_774Z-debug.log
Step #1: The command '/bin/sh -c npm install --unsafe-perm ||   ((if [ -f npm-debug.log ]; then       cat npm-debug.log;     fi) && false)' returned a non-zero code: 1
Finished Step #1
ERROR
ERROR: build step 1 "gcr.io/cloud_builders/docker@sha256:88d8c498fe61a305c35270036827752eaa7d3cc907c6092ed529d870131de440" failed: exit status 1
Step #1: 
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

ERROR: (gcloud.app.deploy) Cloud build failed. Check logs at https://console.cloud.google.com/gcr/builds/90bde4a5-cf43-4bd1-95a4-bac00edfa6e1?project=samparq-198005 Failure status: UNKNOWN: Error Response: [2] Build failed; check build logs for details

Answer №1

The problem can be found here. Here is the solution provided in the response:

We seem to be missing the cairo module () required by the canvas package, causing installation errors. While we figure out how to add the module to the base image, I came across the canvas-prebuilt package (https://www.npmjs.com/package/canvas-prebuilt) which doesn't have the same installation issues. Would you like to give it a try?

This solution worked for me, so it should be effective. I hope it works for you too.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Strategies for packaging and integrating dependencies within Angular-CLI libraries

I am encountering difficulties with bundling dependencies in my project. The library package I have created serves as a wrapper for @angular/material components. To my surprise, each time I install my library package, the installation process also prompt ...

Encountering an installation issue with Angular 2 data table

Is there a solution for resolving unmet peer dependencies during the installation of Angular 2 data table? Here is the issue I am encountering while trying to install it. ...

Capturing all response requests from the main process in Electron: A step-by-step guide

I am looking to retrieve the responses for all requests made in my electron app from the main process. In this image, it shows that the desired response can be found in the Response tab rather than the Headers tab on Chrome Dev Tools. Instead of using a ...

What method works best for setting up Node and npm on a Mac computer?

Just got my hands on a brand new Mac and I'm eager to set up Node and npm on it. Wanting to have full control over the versions I install and remove, can anyone suggest the best method to achieve this? ...

Error: The property 'send' cannot be read because it is undefined - Node.js

We have integrated a Node.js package called springedge to handle SMS functionality in our project: npm install springedge Below is the code snippet from the file send_messages.js: var springedge = require('springedge'); var params = { &apos ...

execute npm postinstall a single time

Is there a way to ensure the postinstall script of npm only runs once, specifically after the initial npm install command is executed? I've searched through the documentation without success. Does anyone know of a method to achieve this without resor ...

Issue encountered when configuring React for the initial setup (event.js:287)

Issue with Command Prompt My attempt to set up react for the first time has been unsuccessful as I keep encountering an error every time I try to run "npm start" or "yarn start" C:\react\reactjs>npm install -g yarn C:\Users\UNC ...

What is the solution for addressing 42 vulnerabilities: 3 considered low severity, 15 moderate, and 24 deemed as high

My Configuration Details: Environment and Versions: nodeJS: v14.18.1 npm: 8.1.1 expo-cli: 4.12.10 OS: MacOS Big Sur 11.6 Contents of my package.json: { "main": "node_modules/expo/AppEntry.js", "scripts": { "star ...

Dependencies for Angular2 Material components on npm

I currently have the following dependencies listed in my package.json for npm to locate and install. "@angular/material": "2.0.0-beta.1" "angular-material": "^1.1.1" If I want to utilize the most up-to-date versions, what exactly should I specify? I am s ...

Post-installation of NPM, configuring CA certificates on Windows system

TLDR; Is there a way to seamlessly set NODE_EXTRA_CA_CERTS in a Windows environment for NPM packages' post-install scripts without requiring system changes, configuration file modifications, or admin-level permissions? Details This issue has been f ...

When NestJS injects an ObjectionJS model, it encounters an exception

Whenever I attempt to inject an Objection.js model into a NestJs service: constructor(@Inject('UserModel') private readonly modelClass: ModelClass<UserModel>) {} I encounter a compile time error stating Maximum call stack size exceeded. I ...

Encountering issues with Vue build on Heroku while implementing Lerna

Currently attempting to set up a Lerna monorepo on Heroku with an Express backend and Vue frontend. The components are stored within /packages/server and /packages/frontend respectively. The goal is to compile the Vue frontend during deployment and serve i ...

Developing a package of modular components for distribution on NPM

Currently, I am in the process of developing an npm package that will contain a collection of React components used in some of the applications I maintain. The goal is to be able to import these components individually as required, rather than all at once ...

Error occurred while installing PWA Studio due to incorrect package manager selected

Running yarn install (node -e 'process.env.CI||process.exit(1)' || npx npm-is yarn) on https://github.com/magento/pwa-studio.git throws an error: /Users/name/.npm/_npx/eb07260b9bcce2ea/node_modules/npm-is/npm-is.js:67 throw new WrongPackageMa ...

What are some tips for incorporating GitHub secrets into a .npmrc file?

In my GitHub project, I have multiple dependencies that are all hosted on the GitHub Package Registry. I rely on GitHub actions to publish these packages. While I can easily utilize GitHub secrets in my workflow.yml file, I am facing challenges when it com ...

I used npm to install AngularJS and then included AngularJS in my application

My goal is to set up AngularJS v1.5.x using npm and integrate it into my application for seamless utilization. Most tutorials opt for downloading the Angular Version from angularjs.org and manually adding it to the index.html within a <script></sc ...

Factors to keep in mind when it comes to managing packages in operating systems

I'm currently exploring different technologies for an upcoming web development project. One crucial factor to consider is package management. I am leaning towards using NPM or bower, but open to other recommendations. Do specific operating systems ( ...

The NativeScript creation process encountered an error: getaddrinfo ENOTFOUND

For those using NativeScript version 0.9.1 I have been following the setup instructions for Windows found here. I am currently facing an issue while creating a new NativeScript project with the command: nativescript create NativeScriptTest --log trace T ...

What is the preferred method of compiling Sass: utilizing the Live Sass Compiler extension in VS Code, or setting up and running Sass through npm? (Including guidance on transitioning from node-sass to dart-sass)

As I delve into an online course focused on Advanced CSS and Sass, I have noticed that the techniques being taught seem a bit outdated. The course heavily relies on node-sass in its dependencies, which is now considered deprecated. An alternative solution ...

Issue with Deploying a Fresh React Application - Is the problem with HTML or index.js?

Welcome, esteemed guests. Today marks the launch of my very first React web app portfolio as I step into the domain of potential employers. However, I have encountered a hurdle in creating an optimized production build that has left me with the message &ap ...